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

2
  • Can You give some lines of your data to reproduce the error? Commented Feb 24, 2013 at 7:45
  • Here is some of my data Commented Feb 24, 2013 at 8:18

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

7 Comments

By file do u mean the name of my excel spreadsheet?...or simply the name of my data frame
Can you tell me why I got this error? Error: unexpected input in "file <- C:\"....my file location is C:\Users\Marco\Documents\value.csv
How do u get the text argument??
What happens when the missing data isn't at the right end of the row?
@ClaytonStanley whatever the position of the missing data, it will be filled with NA.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.