3

So I have an excel spreadsheet with NA values....What is the best way to copy the data and put it in R...I usually use data=read.delim("clipboard").... But because of those missing values....I keep getting this error

Error in if (del == 0 && to == 0) return(to) : 
  missing value where TRUE/FALSE needed

What are the possible ways I can get rid of this error?...I tried putting zeros instead of NA values but that kinda screws up the what the code is doing

Heres the link of the code that I'm using R programming fixing error was really helpful for my data problems.
I was gonna post the whole set but theres a limit of 30000 characters

Community
  • 1
  • 1

1 Answers1

4

You need to set option fill to TRUE , This will let you in case the rows have unequal length, to add NA fields.

   read.table(fileName,header=TRUE,fill=TRUE)

fileName here is your excel file path. for example filename ='c:\temp\myfile.csv'.

This should work also with read.delim which is a wrapper of read.table. You can give read.table a string , but you set the text argument not the file one. For example:

read.table(text = '    Time Speed   Time    Speed
0.8 2.9 0.3 2.7
1.3 2.8 0.9 2.7
1.7 2.3 2.5 3.1
2.0 0.6 
2.3 1.7 13.6    3.3
3.0 1.4 15.1    3.5
3.5 1.3 17.5    3.3',head=T,fill=T)

  Time Speed Time.1 Speed.1
1  0.8   2.9    0.3     2.7
2  1.3   2.8    0.9     2.7
3  1.7   2.3    2.5     3.1
4  2.0   0.6     NA      NA
5  2.3   1.7   13.6     3.3
6  3.0   1.4   15.1     3.5
7  3.5   1.3   17.5     3.3
agstudy
  • 119,832
  • 17
  • 199
  • 261