[R] Apply function to two variables

Erik Iverson eriki at ccbr.umn.edu
Mon Aug 2 19:00:03 CEST 2010


> I would like to apply a function to two vectors 
> 
> For example,
> 
> A<-c(NA,1,2,3,NA)
> B<-6:10
> 
> I would like C to be equal to A but if any A element is NA that
> corresponding c element is equal to B, i.e.
> 
> C = c(6,1,2,3,10)

#untested...
C <- ifelse(is.na(A), B, A)



More information about the R-help mailing list