Reputation: 223
I am trying to read a data table into R. The data contains:
Some values are missing, and they are replaced with either ?
or some spaces and then ?
. As a result, when I read the table into R, the numbers were read as characters.
For example, if Data[1,1]=125, when I write is.numeric(Data[1,1])
I get FALSE. I want to turn all the numbers into numbers, and I want all the ?
(with or without spaces before) into missing values. Do not know how to do this. Thank you! (I have 3279 rows).
Upvotes: 0
Views: 106
Reputation: 70266
You can specify the na.strings
argument of ?read.table
to be na.strings = c("?", "?.")
. Use that inside the read.table()
call when you read the data into R. It should then by recognised correctly. Since you also have some spaces in your data, you could additionally use the strip.white = TRUE
argument inside the read.table
call.
Upvotes: 3