r - How to populate missing match value -
i using match function when match not found want text returned:
input
map<-c("hi","bye") r<-data.frame(x= c("bye","hi",3909090)) r$y<- c(100,200,300) r r$matchcolumn <- map[ match(r$x,map) ] r is.na(r$matchcolumn)
output
> r x y 1 bye 100 2 hi 200 3 3909090 300 > r$matchcolumn <- map[ match(r$x,map) ] > r x y matchcolumn 1 bye 100 bye 2 hi 200 hi 3 3909090 300 <na> ####################### can see na here > is.na(r$matchcolumn) [1] false false true
i want r this:
> r x y matchcolumn 1 bye 100 bye 2 hi 200 hi 3 3909090 300 missing data
i want thinking use is.na(r$matchcolumn) somehow idea?
thank you.
is you're looking for?
r$matchcolumn[is.na(r$matchcolumn)] <- 'missing data'
Comments
Post a Comment