> On May 17, 2017, at 12:18 PM, Davide Piffer <pifferdav...@gmail.com> wrote: > > I need to convert each vector of a dataframe into a matrix with 2 rows > and 2 columns (i.e. contingency table). > Note I don't want to convert the entire df into a matrix! I want to > apply a function that converts each 4 elements vector of a df into a 2 > x 2 matrix. > > I wrote something like this, but it will not work: > > f_matrix=function(x){ matrix (x) > nrow=2} > matrix_y=apply(y,2,function(x) f_matrix (x))
Maybe it shold be: matrix_y_list = lapply(y, function(x) f_matrix (x) ) > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius Alameda, CA, USA ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.