参考这个 DATA[is.na(DATA)] <- 0 (把NA换成0)

参考这个 DATA[is.na(DATA)] <- 0 (把NA换成0)

空格在你的dataframe显示为什么?

如果就是空格的话,dat <- as.numeric(data) 能否把空格转换为NA?

 

有个例子:
data.txt内容为:
sex,height,weight
F,158,51
F,162,55
M, ,72
M,173,57
M,166,64

在R读入时,空白变为NA

> x <- read.table(“data.txt”,header=TRUE,sep=”,”)
> x
sex height weight
1 F 158 51
2 F 162 55
3 M NA 72
4 M 173 57
5 M 166 64

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>