I have a question regarding updating a list
for example I have a string list,
a <-"aab"
b <-"aac"
c <-"aad"
...
newlist<-list(a,b,c...)
I would like to update add "c" for every element by using lapply. the expecting results would be:
> updated_list
[1]aabc
[2]aacc
[3]aadc
...
CodePudding user response:
You can use paste0
as the function argument to lapply
:
updated_list <- lapply(newlist, function(x) paste0(x, "c"))
CodePudding user response:
Can also do
lapply(newlist, paste0, "c")
or
as.list(paste0(unlist(newlist), "c"))