Home > Software design >  how to add a non-empty df into a list
how to add a non-empty df into a list

Time:08-13

I have a list lst1 and a dataframe from another list lst2[[df]]. If I want to append df to lst1 with the condition !is.null(lst2[[df]]), what should I do? I would like to know the way if I use lapply as well as append

For append, I think we can do append(lst1, list(lst2[[df]]). I am not sure where to add condition. I also have the doubt on list(lst2[[df]]) part. Could anyone guide me on this?

Thanks.

CodePudding user response:

We can use the condition in if (assuming df is an object for the list name)

if(!is.null(lst2[[df]])) lst1[[df]] <- lst2[[df]]
  •  Tags:  
  • r
  • Related