Reputation: 133
> list1<-list("A1","A2")
> str(list1)
List of 2
$ : chr "A1"
$ : chr "A2"
> list1<-paste(list1,"example",sep=" ")
> str(list1)
chr [1:2] "A1 example" "A2 example"
I had wanted to preserve the list structure, but it seems like pasting new values into the list changes it.
How should I go about writing the code without affect the structure?
Thanks.
Upvotes: 2
Views: 139
Reputation: 388982
Use []
to preserve the structure.
list1[] <- paste(list1,"example")
str(list1)
#List of 2
# $ : chr "A1 example"
# $ : chr "A2 example"
Upvotes: 2