Re: [R] Data comparison

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Sat 18 Jun 2005 - 05:24:55 EST

On 6/17/2005 12:33 PM, dscully@fd9ns01.okladot.state.ok.us wrote:
>
>
>
> Question : Is it possible to create a function, using a for ifelse
> function, inside sapply, to compare the values in one data frame to a set
> of upper and lower limits in another data frame, same number of columns.,
> Take the values which meet the requirements "TRUE" and create a new data
> frame or table containing the filtered data? Can you give me a shove in
> the correct direction? Thanks

I think you don't need a function within sapply. You just want something like this:

 > df1 <- data.frame(x = runif(20))
 > y <- runif(20)
 > df2 <- data.frame(lower = y, upper = y + runif(20))
 >
 > df3 <- cbind(df1, df2)
 >
 > df3[(df2$lower < df1$x) & (df1$x < df2$upper), ]
            x     lower     upper
5  0.6688050 0.4357477 0.6786472
6  0.5608836 0.4649370 0.8596602
8  0.5109508 0.2654933 1.0573998
9  0.5966776 0.3035084 0.9834681

19 0.3787230 0.1894318 0.6783048
20 0.2826356 0.2321261 1.0913582

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Jun 18 05:28:44 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:32:49 EST