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

1 Answer

+1 vote
by (348k points)
selected by
 
Best answer

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)

Related questions

+5 votes
1 answer
+5 votes
1 answer
+2 votes
1 answer

...