[R] read dataset with blank space as missing value
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Apr 20 06:39:14 CEST 2006
There are a number of approaches:
1. This will identify the line numbers of the short lines
and then you can fix them up by hand.
k <- count.fields(myfile)
which(k < max(k))
2. If you can assume that 4 spaces, say, represents a missing
value then:
L <- readLines(myfile)
L <- gsub(" ", " . ", L)
read.table(textConnection(L), na.strings = ".")
On 4/20/06, Yong Wang <wangyong1 at gmail.com> wrote:
> Dear R users
>
> As specified in the subject, a dataset as following:
>
> 56 a 1 2 3 4 5 6 7
> 234 b 2 3 5 . 8 1 9
> 457 b 2 4 6 7 3 3 <--the blank space should be missing value
> 658 f 2 3 5 6 8 1 9
>
> the blank space at thethird row should be missing value. how should I
> deal with this. fill=T will move "4" to the blank space which is not
> desired.
>
> thank you
>
> yong
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
More information about the R-help
mailing list