Aim
Replace NA
with "Nothing"
in character vector
Input
data<-c(NA, NA, "SupineAcid", NA, NA, NA, "UprightAcid", "UprightAcid",
NA, NA, "UprightAcid", NA, "UprightAcid", NA, NA, "UprightAcid",
"TotalAcid", NA, NA, NA)
Attempts
gsub(NA,"dd",data)
This leads to all the results being NA
I've also tried with "NA"
and fixed=TRUE
but the same issue.
In order to change the NA
elements in your vector, you can use the is.na
function:
data[is.na(data)] = "dd"
"dd" "dd" "SupineAcid" "dd" "dd" "dd" "UprightAcid"
"UprightAcid" "dd" "dd" "UprightAcid" "dd" "UprightAcid" "dd"
"dd" "UprightAcid" "TotalAcid" "dd" "dd" "dd"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With