R更改NA值 [英] R Change NA values
本文介绍了R更改NA值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据如下所示: http://imgur.com/8KgvWvP
My data looks like this: http://imgur.com/8KgvWvP
我想将NA
的值更改为每列的另一个值.
例如,在包含NA
,Single
和Dual
的列中,我想将所有NA
更改为'Single'
.
I want to change the values NA
to another value for each column.
For example in the column that contains NA
, Single
and Dual
, I want to change all the NA
to 'Single'
.
我尝试了以下代码:
data_price$nbrSims <- ifelse(is.na(data_price$nbrSims), 'Single', data_price$nbrSims)
但是随后我的数据如下所示,其中Dual
变为2
和Single
1
.
http://imgur.com/TC1bIgw
But then my data looks like this, where Dual
became 2
and Single
1
.
http://imgur.com/TC1bIgw
如何在不更改其他值的情况下更改NA
值?
预先感谢!
How can I change the NA
values, without changing the other values?
Thanks in advance!
推荐答案
尝试一下(检查哪些是NA
,然后将其替换为"Single"
):
Try this (check which are NA
and than replace them with "Single"
):
data_price$nbrSims <- as.character(data_price$nbrSims)
data_price$nbrSims[is.na(data_price$nbrSims)] <- "Single"
这篇关于R更改NA值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文