[R] Rows of a data frame to matrix

Damian Betebenner damian.betebenner at bc.edu
Mon Sep 25 21:33:08 CEST 2006


useRs,

I have a data frame where four of the columns of the data frame represent the values of a two-by-two
matrix. I'd like to, row-by-row, go through the data frame and use the four columns, in matrix form, to
perform calculations necessary to create new values for variables in the data frame. My first idea was to 
use apply:

apply(as.array(data.frame[,1:4]), 1, matrix, nrow=2)

Though intuitive, this doesn't work. I've stumbled in the dark with mApply and other functions but can't
find anything in the help that works. This can't be that hard, but it has me stumped. 

Any help greatly appreciated,

Damian



More information about the R-help mailing list