How can I rewrite the for loop in the following piece of code using lapply?
transactions <- read.table(file = file("stdin"), header = FALSE, stringsAsFactors = FALSE)
for (i in 1:nrow(transactions)) {
transactions[i,1] <- paste(sort(unlist(strsplit(transactions[i,1], ","))), collapse = ",")
}
If you find it easier to work with some input data, use the following as the contents of stdin:
a,b
b,c,a
a,b,c
b,a,c
a,b,c,d
a,d,b,c
It looks like you want to sort the individual comma-separated components of
transactions[, 1].