[R] Data comparison
Duncan Murdoch
murdoch at stats.uwo.ca
Fri Jun 17 21:24:55 CEST 2005
On 6/17/2005 12:33 PM, dscully at 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
More information about the R-help
mailing list