+1 vote
in Programming Languages by (7.3k points)
I want to append a new element to an existing list. What function should I use?

1 Answer

0 votes
by (30.2k points)

You can use either append() or c() function to append a new element to an existing R list. In the append() function, you can also mention the position where you want to insert the new element.

Here is an example:

a <- list(1,2,3,4)
a <- append(a,5)
a <- c(a,6)
a <- append(a,7, after = 2)

unlist(a)

...