I have a dataframe where the third column is a list of lists. I wish to add a column to the existing dataframe that consists only of the element of the list where key = wb_id
and the value string is what I want to be in the new column. Previously, I thought that this was always the 14th element in the list. I was wrong, it seems to move around, but it is always identified by key = wb_id
.
So in the example below, there would be a new column, wb_id, added to df that consisted of 2 rows:
> df[[3]][[1]][[14]][["value"]]
[1] "test1_secret_ID"
> df[[3]][[2]][[14]][["value"]]
[1] "test2_secret_ID"
Here is the dataframe
df <- structure(list(email = list("test1@example.com", "test2@example.com"),
type = list("active", "active"), fields = list(list(list(
key = "name", value = "", type = "TEXT"), list(key = "email",
value = "test1@example.com", type = "TEXT"), list(key = "company",
value = "", type = "TEXT"), list(key = "country", value = "",
type = "TEXT"), list(key = "city", value = "", type = "TEXT"),
list(key = "phone", value = "", type = "TEXT"), list(
key = "state", value = "", type = "TEXT"), list(key = "zip",
value = "", type = "TEXT"), list(key = "last_name",
value = "", type = "TEXT"), list(key = "notify_pref",
value = "new_leader", type = "TEXT"), list(key = "your_message",
value = "", type = "TEXT"), list(key = "selected",
value = "Canadian Tire Bank,Bridgewater Bank,Motive Financial",
type = "TEXT"), list(key = "confirmed_email", value = "",
type = "TEXT"), list(key = "wb_id", value = "test1_secret_ID",
type = "TEXT")), list(list(key = "name", value = "",
type = "TEXT"), list(key = "email", value = "test2@example.com",
type = "TEXT"), list(key = "company", value = "", type = "TEXT"),
list(key = "country", value = "", type = "TEXT"), list(
key = "city", value = "", type = "TEXT"), list(key = "phone",
value = "", type = "TEXT"), list(key = "state", value = "",
type = "TEXT"), list(key = "zip", value = "", type = "TEXT"),
list(key = "last_name", value = "", type = "TEXT"), list(
key = "notify_pref", value = "new_leader", type = "TEXT"),
list(key = "your_message", value = "", type = "TEXT"),
list(key = "selected", value = "Canadian Tire Bank,Bridgewater Bank,Motive Financial",
type = "TEXT"), list(key = "confirmed_email", value = "",
type = "TEXT"), list(key = "wb_id", value = "test2_secret_ID",
type = "TEXT"))), date_created = list("2020-10-24 01:57:10",
"2020-10-24 01:57:23")), row.names = 1:2, class = "data.frame")