My data looks like this: http://imgur.com/8KgvWvP
I want to change the values NAto a different value for each column. For example, in the column containing NA, Singleand Dual, I want to change everything NAto 'Single'.
NA
Single
Dual
'Single'
I tried this code:
data_price$nbrSims <- ifelse(is.na(data_price$nbrSims), 'Single', data_price$nbrSims)
But then my data looks like this: Dualbecame 2and Single 1. http://imgur.com/TC1bIgw
2
1
How to change values NAwithout changing other values? Thanks in advance!
, 1 2 ifelse, factor. character,
ifelse
factor
character
data_price$nbrSims <- as.character(data_price$nbrSims) data_price$nbrSims <- ifelse(is.na(data_price$nbrSims), 'Single', data_price$nbrSims)
(, NA "Single"):
"Single"
data_price$nbrSims <- as.character(data_price$nbrSims) data_price$nbrSims[is.na(data_price$nbrSims)] <- "Single"
To be clear, Martha’s answer is right.
You can also change all Na values using this
data_price[is.na(data_price)]<-"Something"
Source: https://habr.com/ru/post/1623737/More articles:Images not showing securely connected to Amazon S3 - ruby-on-railsadd image from db to sql report query - c #wicked pdf не отображается amazon s3 images - amazon-web-servicesAdd host to known_hosts file without prompting - ansibleRcpp passes a vector of length 0 (NULL) to the cppunction function - rDjango: How to access current user id in javascript? - javascriptCould not install "Cairocffi" - pythonZeppelin throws java.lang.OutOfMemoryError: Java heap space - apache-sparkHow does merge without branch work? - gitProxy settings npm escape '\' char - node.jsAll Articles