Create new list/data frame from a value in a list within a data frame in R
If I understand what you are asking, you have a list, and the easiest way is to iterate with the apply
functions:
df_new <- data.frame(
uniqueID = df$uniqueID,
pval = sapply(df$res, function(x) x[["p.value"]])
)
Output:
r$> df_new
uniqueID pval
1 101030 1.5e-04
2 101060 4.5e-05
We can also hoist
the p.value
column up one nested level:
library(tidyr)
library(dplyr)
hoist(df, .col = res, "p.value") %>%
select(uniqueID, p.value)
#> # A tibble: 2 × 2
#> uniqueID p.value
#> <chr> <dbl>
#> 1 101030 0.00015
#> 2 101060 0.000045