I come across lists that I would like to parse before they are entered into the data frame. Sometimes I have lists that have items that I don't expect. I would like to remove all of these unexpected items by name when they occur. Below is an example of a list with a wackything element that I would like to delete without calling the index of the element or using the for loop through each subitem.
my_list <- list(person = list(name = "mike", phone = "111-1111"), person = list(name = "lisa", phone = "222-2222", wackything = "PLEASE REMOVE ME"), person = list(name = "kimo", phone = "333-3333"))
I want my last list to look like this:
final_list <- list(person = list(name = "mike", phone = "111-1111"), person = list(name = "lisa", phone = "222-2222"), person = list(name = "kimo", phone = "333-3333"))
so that I can bind it to a data frame using
do.call(rbind, lapply(final_list, rbind))
source share