如何将数据帧
raw_df
逐行传输到list
? 结果为wished_list
library(tidyverse)
raw_df <- data.frame(cat=c('a','b','c'),value=c('high','mid','low'))
wished_list <- list(a='high',b='mid',c='low')
一种选择是:
as.list(setNames(raw_df$value, raw_df$cat))
$a
[1] "high"
$b
[1] "mid"
$c
[1] "low"