Creating complex list structure from data frame in R -


i'm looking create list of lists data frame in r.

my data frame looks this:

  name    age 1 john    30 2 dan     40 3 charlie 20 ...(few thousand rows)... 

and trying produce list such keys list names in data frame, , each key/name points list list(age=30)

in end, i'm looking

 > str(list(john=list(age=30),dan=list(age=40),charlie=list(age=20),...))  list of 3   $ john   :list of 1    ..$ age: num 30   $ dan    :list of 1    ..$ age: num 40   $ charlie:list of 1    ..$ age: num 20   ... 

z        <- lapply(df$age,function(x)list(age=as.numeric(x))) names(z) <- df$name str(z) # list of 3 #  $ john   :list of 1 #   ..$ age: num 30 #  $ dan    :list of 1 #   ..$ age: num 40 #  $ charlie:list of 1 #   ..$ age: num 20 

Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -