[R] How to DataFrame[..==..] <- NA ?

Christian Hoffmann christian.hoffmann at wsl.ch
Wed Feb 21 09:18:28 CET 2001


Hi all,

I have a dat frame U2
> dim(U2) 
1442  174

I am stuck at a point which S-Plus3.4 went smoothly. In R-1.2.1 (compiled
on Solaris5) I am getting:

> U2[U2 == -9] <- NA
 Error in [<-.data.frame(*tmp*, U2 == -9, value = NA) : 
 matrix subscripts not allowed in replacement

I tried some work-arounds:

> U2[which(U2 == -9)] <- NA
  Error in [<-.data.frame(*tmp*, which(U2A == -9), value = NA) : 
 new columns would leave holes after existing columns

> U2[which(U2 == -9)] <- list(NA)  # the same error

With the function
> function (arr, func, ...) array(func(as.vector(arr), ...), dim(arr),
dimnames(arr))

> U2x <- vapply(U2,function(x)  ifelse(x == -9,NA,x))
 Error in rep(no, length = length(ans)) : Unimplemented feature in rep


By the way:
>length(which(U2 == -9))
5273
>length(which(is.na(U2)))
194

I would be glad to learnt what went wrong here.


-christian
Dr.sc.math.Christian W. Hoffmann
Mathematics and Statistical Computing
Landscape Modeling and Web Applications
Swiss Federal Research Institute WSL 
Zuercherstrasse 111
CH-8903 Birmensdorf, Switzerland
phone: ++41-1-739 22 77    fax: ++41-1-739 22 15
e-mail: Hoffmann at WSL.CH
www: http://www.wsl.ch/staff/christian.hoffmann/

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list