[R] extracting rows from data frame that approximately equal another data frame

arun smartpink111 at yahoo.com
Thu Jan 16 22:34:37 CET 2014


May be this helps:
x <- data.frame(V1=-1.162877, V2=0.1848928)
df <- as.data.frame(matrix(rnorm(5051*2),ncol=2))

 cut1 <- cut(df[,1],breaks=c(x[,1]-0.1,x[,1]+0.1))
 cut2 <- cut(df[,2],breaks=c(x[,2]-0.1,x[,2]+0.1))

df1 <- df[!is.na(cut1) & !is.na(cut2),]


I have a dataframe and would like to extract rows that approximately equal to the values in another data frame. 

say I have a data frame called x 

[1] 1 2 

          V1        V2 
x -1.162877 0.1848928 

I would like to search through a larger data frame 
called df and extract all rows that approximately equal the two values 
in the data frame x by say +- 0.1. 

The larger dataframe has these dimensions 

[1] 5051    2

More information about the R-help mailing list