Sören;
You need to somehow add back to the information that is in "l" that
fact that it was sampled from a set with 4 elements. Since you didn't
sample from a factor the level information was lost. Otherwise, you
coud create that list with unique(l) which in this case only returns 3
eleme
one way is:
set.seed(20)
l <- sample(rep.int(c("locA", "locB", "locC", "locD"), 100), 10, replace=T)
f <- factor(l, levels = paste("loc", LETTERS[1:4], sep = ""))
m <- as.data.frame(model.matrix(~ f - 1))
names(m) <- levels(f)
m
I hope it helps.
Best,
Dimitris
soeren.vo...@eawag.ch wrote:
H
2 matches
Mail list logo