[R] Conditional operation on multiple columns from two data frames

Peter Dalgaard p.dalgaard at biostat.ku.dk
Mon Dec 29 01:52:55 CET 2008


tsippel wrote:
> The suggestion below was made.
> 
> df1$Date <- as.Date(df1$Date)
> df2$Date <- as.Date(df2$Date)
>  
> ifelse(df1$ID==df2$ID & df1$Date-df2$Date<0.5,df1$y-df2$y, NA)
> 
> However, because my dataframe rows do not align, I need the conditionals to
> be tested on every combination of cells.  I'm starting to think I need to
> use tapply?  
> 
> Tim  

I'd look at outer() or try a merge() before the operation to get things 
aligned. It is not clear to me what form of output you desire if you 
look at "every combination of cells".

-- 
    O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
   c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
  (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-help mailing list