[R] paste and NAs
Benjamin.STABLER@odot.state.or.us
Benjamin.STABLER at odot.state.or.us
Wed Jul 23 20:09:17 CEST 2003
I understand how R treats NAs but in the situation below it would be nice to
have a na.skip argument to paste so it does not convert the NAs to "NA"s and
simply skips those elements of the vector for pasting.
> x
[1] "2.13" "2.3" NA NA "2.83" NA
> paste(x, "0", sep="")
[1] "2.130" "2.30" "NA0" "NA0" "2.830" "NA0"
With na.skip argument:
paste(x, "0", sep="", na.skip=T)
[1] "2.130" "2.30" NA NA "2.830" NA
Otherwise I will use:
y <- paste(x, "0", sep="")
gsub(paste("NA","0",sep=""),"", y)
"" is not the same as NA, but for my purposes "" is close enough. Why can't
I use NA as a replacement in gsub, even though c("a", NA) works?
Benjamin Stabler
Transportation Planning Analysis Unit
Oregon Department of Transportation
555 13th Street NE, Suite 2
Salem, OR 97301 Ph: 503-986-4104
More information about the R-help
mailing list