Reputation: 119
I have composed the following dataframe and i want to add the "values" contents as rows in the dataframe. So the values column contains lists which contain a dataframe. This is what i'm currently using without success.
name <- c("impressions_unique", "impressions_paid_unique","impressions_organic_unique")
period <- c("lifetime","lifetime","lifetime")
l1 <- list(data.frame(value = 33395))
l2 <- list(data.frame(value = 0))
l3 <- list(data.frame(value = 33395))
values <- c(l1,l2,l3)
title <- c("Lifetime Post Total Reach","Lifetime Post Paid Reach","Lifetime Post organic reach")
description <- c("Lifetime","Lifetime","Lifetime")
id <- c(125698,432566,759832)
df <- data.frame(name,period,values,title,description,id)
Now each object of the values column becomes another column in the dataframe, which i want it to be a row ,that contains a list instead. Any help will be much appreciated.
Upvotes: 1
Views: 47
Reputation: 389235
Add the list column separately.
df <- data.frame(name,period,title,description,id, stringsAsFactors = FALSE)
df$values <- values
df
# name period title description id values
#1 impressions_unique lifetime Lifetime Post Total Reach Lifetime 125698 33395
#2 impressions_paid_unique lifetime Lifetime Post Paid Reach Lifetime 432566 0
#3 impressions_organic_unique lifetime Lifetime Post organic reach Lifetime 759832 33395
Upvotes: 1