Search code examples
rdataframelist

How to transfer dataframe `raw_df` to `list` row by row?


How to transfer data frame raw_df to list row by row? Desired output: wished_list

 raw_df <- data.frame(cat=c('a','b','c'),value=c('high','mid','low'))
 wished_list <- list(a='high',b='mid',c='low')

Solution

  • One way to solve your probem:

    split(raw_df$value, raw_df$cat)
    
    $a
    [1] "high"
    
    $b
    [1] "mid"
    
    $c
    [1] "low"