On Sun, Feb 05, 2012 at 06:54:02AM -0800, Alaios wrote:
> Dear all
> I am using lapply (actually mclapply that share the same syntax).
> 
> I want to call the same function that takes as input a vector. My initial 
> data structure is a matrix that I want to cut it to multiple vectors (one 
> vector for every row of the matrix) and then feed that to the function by 
> using mclapply.
> 
> Could you please help me converting the matrices to nrow times vectors.

Hi.

Try the following

  a <- matrix(1:16, nrow=4)
  x <- lapply(apply(a, 1, FUN=list), unlist)
  x

  [[1]]
  [1]  1  5  9 13
  
  [[2]]
  [1]  2  6 10 14
  
  [[3]]
  [1]  3  7 11 15
  
  [[4]]
  [1]  4  8 12 16

Hope this helps.

Petr Savicky.

______________________________________________
R-help@r-project.org mailing list
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.

Reply via email to