我有大约 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)
由于必须读入的文件在某些列之间有多个空格作为分隔符,因此上述方法不起作用。有什么方法可以让我们有效地读取这个文件。