[R] Problems replacing empty cells with NA values

jim holtman jholtman at gmail.com
Sat Jan 29 02:44:05 CET 2011


Do 'str(data)' to see what the structure of the data is.  Are the
columns with <NA> character or factors?  Is this what you are seeing:

> x <- read.table(textConnection('123 456 a
+ NA 1 b
+ 2 NA c
+ 3 4 NA
+ 3 2 1'))
> closeAllConnections()
> x
   V1  V2   V3
1 123 456    a
2  NA   1    b
3   2  NA    c
4   3   4 <NA>
5   3   2    1
> str(x)
'data.frame':   5 obs. of  3 variables:
 $ V1: int  123 NA 2 3 3
 $ V2: int  456 1 NA 4 2
 $ V3: Factor w/ 4 levels "1","a","b","c": 2 3 4 NA 1
> sum(is.na(x$V3))
[1] 1
>


On Fri, Jan 28, 2011 at 12:28 PM, Simone Santoro <miseno77 at hotmail.com> wrote:
>
> Hi,
>
> I am preparing a quite huge database in Excel, I replaced the empty cells with "NA", I formatted it like text, and saved the file like a *.txt.
> After, in R:
>
> data<-read.table("myfile.txt",header=T,sep="\t")
> edit(data)
>
> When doing this I can see that some columns are OK and they have NA cells, but other columns are not (there are empty cells where there should be NAs).
> Surprisingly (at least to me), when I close the "edit window" I can see all the data in the "R console" (automatically closing that windows makes starting the visualization of those data in the same R console window) and there are not empty cells but, nevertheless, some columns have NA values but other ones have <NA> values.
> Why?
> Could it possibly cause any problem to the analysis?
>
> Thanks
> Best wishes
>
> Simone
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list