如何将数据帧`raw_df`逐行传输到`list`?

问题描述 投票:0回答:1

如何将数据帧

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')
r dataframe list
1个回答
1
投票

一种选择是:

as.list(setNames(raw_df$value, raw_df$cat))

$a
[1] "high"

$b
[1] "mid"

$c
[1] "low"
© www.soinside.com 2019 - 2024. All rights reserved.