[R] create a r list from dataframe using the first column as list names

Rasmus Liland jen@r@@mu@ @end|ng |rom gm@||@com
Thu Apr 9 19:28:57 CEST 2020


On 2020-04-09 15:00 +0000, aiguo li via R-help wrote:
| Hello allI need to create a r list with 
| each row as a list object and named with 
| the element in the first column.  

Dear aiguo,

Perhaps this fits your bill?

  a <- matrix(LETTERS[1:16], nrow = 4)
  FUN <- function(x) { as.factor(x[-1]) }
  lapply(X=split(a, a[,1]), FUN=FUN)

Best,
Rasmus



More information about the R-help mailing list