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)),
Hi Thomas,
It depends whether you'd like to include all levels of each column in every
column. For including all values you could try something like this:
isAllDifferent <- function(z) !any(duplicated(z))
myData <- data.frame(Friend1=c("a", "a", "b", "c"), Friend2=c("b", "c
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
3 matches
Mail list logo