I try to perform a simple lm()
regression analysis on a data frame. Explicitly, I want to perform a regression analyses between the column names of the data frame and each row. My data frame looks like this:
d = data.frame(replicate(6,rnorm(6)))
colnames(d) = as.character(0:5)
However, my lm()
does not work:
lm(d[1,]~colnames(d))
#Error in model.frame.default(formula = d[1, ] ~ colnames(d), drop.unused.levels = TRUE) :
#invalid type (list) for variable 'd[1, ]'
I would very much appreciate if someone helps me to get this running. I have not used much the lm()
function, yet.
I know that the lm()
functions wants something in the format lm(columnA ~ columnB, data = mydata)
, so I tried to to build a data frame for my data before posting the question here:
cbind(d[1,],0:5)
This, however, does not drop the dimensions of d
. No clue why. If one can answer this questions, too, even though more general about R understanding would help me big time.