Hi Friends,

I have a data frame d. Let vars be the column indices for a subset of the columns in d (e.g., vars <- c(1,3,4,8))

For each row r in d, I want to collect all the other rows in d that match the values in row r for just the columns in vars.

The naive way to do this is to have a for loop stepping through each row in d, and within the loop have another loop going through all the rows again, checking for equality. This is quadratic in the number of rows and takes way too long. Is there a better, "vectorized" way to do this?

Thanks in advance!

Rama Ramakrishnan

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to