Probably about 20 chars’ solution. I want colnames to matrix(...) -object or alternative way to create 6×100 dataframe with zeros and colnames:
matrix(rep(0,600),ncol=6)->M
where to access things with title-ids likecol$id and now to access 97th element in col a1 in the matrix, I want to do M$a1[97]. How?
Errr
> matrix(rep(0,600),ncol=6,nrow=100, colnames=c('q1','q2','a1','a2','s1','s2'))
Error in matrix(rep(0, 600), ncol = 6, nrow = 12, colnames = c("q1", "q2", :
unused argument(s) (colnames = c("q1", "q2", "a1", "a2", "s1", "s2"))
1) Use the
dimnamesparameter in matrix to define column names when creating the matrix. dimnames should be a list of 2 or NULL.From the help page:
Or set the colnames after the fact:
2) Use the
[indexing operator for matrices: