How to transfer dataframe
to list
and not include NA value ? Thanks!
There is dataframe ori_df
library(tidyverse)
ori_df <- data.frame(category=c('a','b',NA),subcategory=c('w',NA,'Z'))
Below code can transfer ori_df
to list fin_list
,but the result include NA
fin_list <- as.list(ori_df)
How to delete NA
value in fin_list
, the wished result as below fin_list_wished
?
fin_list_wished <- list(category=c('a','b'),subcategory=c('w','Z'))
1
Similar to the comment above:
lapply(ori_df, function(x) x[!is.na(x)])