I have a dataset that looks like the one below:

 ID          Message     
  1                .
  2                .
  3     Click_screen
  4     Blank screen
  5                .
  6                .
  7                .

The actual dataset has 48 columns and 50,000 rows.

Importing this dataset with read.table() is problematic because of the string "Blank screen", which has a space between the two sub-strings. For example, I got an error message like:

  Error in scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  : 
     line 4 did not have 48 elements

I wonder if there is any way to circumvent this problem in R rather than change the original dataset in Excel.

EDIT: Just to add, I tried to set fill to TRUE, and I got an error message below:

 Error in read.table(file.choose(), header = T, fill = T) : 
   duplicate 'row.names' are not allowed
有帮助吗?

解决方案

If the file is space-separated (as opposed to tab-separted), you might want read.fwf, along with a vector of field widths. If the file is tab-separated, you might want read.table(sep='\t',...).

其他提示

It depends on your local separator but try this

read.table(fileName,fill=TRUE,header=FALSE,sep =';')
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top