Question

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
Was it helpful?

Solution

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',...).

OTHER TIPS

It depends on your local separator but try this

read.table(fileName,fill=TRUE,header=FALSE,sep =';')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top