我有一个大数据集,由大约 94 列和 300 万行组成。该文件具有单个和多个空格作为列之间的分隔符。我需要在 R 中读取该文件中的一些列。为此,我尝试使用 read.table() 以及可以在下面的代码中看到的选项,代码粘贴在下面-
### Defining the columns to be read from the file, the first 5 column, then we do not read next 24, after this we read next 5 columns. Last 60 columns are not read in-
col_classes = c(rep("character",2), rep("numeric", 3), rep("NULL",24), rep("numeric", 5), rep("NULL", 60))
### Reading first 100 rows of the data
data <- read.table(file, sep = " ",header = F, nrows = 100, na.strings ="", stringsAsFactors= F)
由于要读入的文件在某些列之间有多个空格作为分隔符,因此上述方法不起作用。有没有什么方法可以让我们有效地读取这个文件。