Compare one row to all other rows in a file using R -


I have a similar file:

  P1a, b, cp2b , C, D, FPC3C, D, E, F   

and I need to compare each line with all other rows to get the count of dividing the following lines : P1 P2 2 P1 P3 1 P2 P3 3

Thanks,
S

Read example data.

  txt & lt; - "P1A, B, CP2B, C, D, FPC3C, D, E, F." TC & LT; - Text connection (TSTT) data & lt; Close the read.table (TC, as.is = TRUE) (TC)   

Convert long format and use the self with the integrated function.

  dat_split & lt; - strsplit (dat $ V2, ",") dat_long & lt; - do.call (rbind, lapply (seq_along (dat_split), function (x) data .frame (id = x, x = dat_split [[x]], stringsfactor = FALSE) result & lt; - sqldf ("SELECT t1 .id as id1, t2.id as id2, count (t1.x) AS N dTialong AS T1 inner join hold_language ATT2 WHERE (T2ID & gt; T.Id) and (T1X = T 2.X) Group by T.ID, T.ID ")   

Result

 > Results ID1 ID2N1 1 2 2 2 1 3 1 3 2 3 3    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -