Here is my code for building a design matrix for a linear modelling function:
f <- factor(targets$Sample.Name, levels = unique(targets$Sample.Name))
design <- model.matrix(~0 + f)
colnames(design) <- levels(f)
Am not sure how to interpret the formula "~0". I looked up ?lm() and found that if a formula has an implied intercept term one can remove this using either y ~ x - 1 or y ~ 0 + x, but am not sure if this is the same case here.
Yes it's the same case here. You can examine the output from
design
to check.