Re: [R] Combinations of values in two columns

2013-11-01 Thread arun
Hi, You may try: dat1 <- read.table(text=" Friend1,Friend2 A,B A,C B,A C,D",sep=",",header=TRUE,stringsAsFactors=FALSE) indx <- as.vector(outer(unique(dat1[,1]),unique(dat1[,2]),paste)) res <- cbind(setNames(read.table(text=indx,sep="",header=FALSE,stringsAsFactors=FALSE),paste0("Friend",1:2)),

Re: [R] Combinations of values in two columns

2013-11-01 Thread Chris Campbell
re. SN14 OGB UK -----Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Thomas Sent: 01 November 2013 09:32 To: r-help@r-project.org Subject: [R] Combinations of values in two columns I have data that looks like this: Friend1, Frien

Re: [R] Combinations of values in two columns

2013-11-01 Thread Simon Zehnder
You could use the data.table package require(data.table) DT <- data.table(Friend1 = sample(LETTERS, 10, replace = TRUE), Friend2 = sample(LETTERS, 10, replace = TRUE), Indicator = 1) ALL <- data.table(unique(expand.grid(DT))) setkey(ALL) OTHERS <- ALL[!DT] OTHERS[, Indicator := 0] RESULT <- rbi

[R] Combinations of values in two columns

2013-11-01 Thread Thomas
I have data that looks like this: Friend1, Friend2 A, B A, C B, A C, D And I'd like to generate some more rows and another column. In the new column I'd like to add a 1 beside all the existing rows. That bit's easy enough. Then I'd like to add rows for all the possible directed combination