[英]Remove NAs from data frame
I have my data as follows: 我的数据如下:
Date Med1 Med2 Med3 Med4
2013-03-01 19 23 NA 33
2013-03-01 25 NA 19 27
2013-03-01 26 23 15 NA
2013-03-01 NA 27 NA 25
I would want my data in the following format: 我希望我的数据采用以下格式:
Date Med1 Med2 Med3 Med4
2013-03-01 19 23 33
2013-03-01 25 19 27
2013-03-01 26 23 15
2013-03-01 27 25
ie, I want to replace the NAs with empty cells. 即,我想用空单元格替换NA。
I tried functions such as na.omit(df)
, na.exclude(df)
. 我尝试了诸如na.omit(df)
, na.exclude(df)
函数。 In both the cases, the row which has NA is being omitted or excluded. 在这两种情况下,具有NA的行都将被省略或排除。 I dont want to drop off the entire row or column but just the NA. 我不想删除整个行或列,而只删除NA。
Please note that I dont want the NAs to be replaced by 0s. 请注意,我不希望将NA替换为0。 I want a blank space replacing NA. 我想用空白代替NA。
Is there a way to do that? 有没有办法做到这一点?
This can be done as follows: 可以按照以下步骤进行:
df[is.na(df)] <- ""
Thanks Richard! 谢谢理查德!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.