[R] Odp: set values in data.frame to NA conditional on another data.frame

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Thu, 03 Jul 2008 09:01:30 +0200

Hi

is your data all numeric or all character? If yes you can transform it to matrix and then such setting shall be quite quick.

vec<-rnorm(6000*6000)
mat<-vec
dim(mat)<-c(6000,6000)
mat2<-mat
mat2[sample(1:6000, 500), sample(1:6000, 500)]<-NA sum(is.na(mat2))
[1] 250000
> 500*500

[1] 250000
system.time(mat[is.na(mat2)]<-NA)

   user system elapsed
   0.61 0.11 0.72
>
> sum(is.na(mat))

[1] 250000

Regards
Petr

r-help-bounces_at_r-project.org napsal dne 02.07.2008 23:17:44:

> Hello List,
>
> Is there a faster way to set values in one data.frame equal to NA
> conditional on the corresponding value in another data.frame? Currently
> I am using:
> > b[is.na(a)] <- NA
> where 'a' and 'b' are data.frames of equal size/dimensions, and 'a'
> contains NAs but 'b' does not. This is extremely slow as is, as my
> data.frames are about 6000 columns by 6000 rows in size.
> Are there any tricks to speed things up here?
>
> Thank you in advance,
>
> Carson
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Thu 03 Jul 2008 - 07:05:47 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Jul 2008 - 07:31:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive