[R] matching each row

tathta caitlyn.paget at gmail.com
Wed Jul 8 19:45:56 CEST 2009


Close...   

The output I'm looking for is more like this: 

output <-
data.frame(unique.id=c(1,3,5,7,9),N.in.x=c(2,3,1,2,1),N.in.y=c(0,1,3,1,1))

The first column can be gotten using a small change to the first table line: 
table ( x [ which ( x %in% x ) ] )   ##the 3rd "x" used to be a "y"

but I can't modify it to make the second "ideal output" column, I just end
up with warnings...  




Something like this? 

  > dataframeA <- data.frame (
  +   unique.id= c(1,1,3,3,3,5,7,7, 9)
  +   , x1=rnorm(9)
  +   , x2=rnorm(9)
  +   , x3=rnorm(9)
  + )
  > dataframeB <- data.frame (
  +   unique.id= c(2,3,4,5,5,5,6,7,9,10,10)
  +   , x4=rnorm(11)
  +   , x5=rnorm(11)
  +   , x6=rnorm(11)
  + )
  > match.counts <- function ( x , y ) {
  +   out <- cbind (
  +     table ( x [ which ( x %in% y ) ] )
  +     , table ( y [ which ( y %in% x ) ] )
  +   )
  +   dimnames ( out ) [[2]] <- c ( "N in x" , "N in y" )
  +   out
  + }
  > match.counts ( dataframeA$unique.id , dataframeB$unique.id )
    N in x N in y
  3      3      1
  5      1      3
  7      2      1
  9      1      1
  >

--
 David
 
-- 
View this message in context: http://www.nabble.com/matching-each-row-tp24393051p24396184.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list