0

I have 1 list A containing 2 vectors and 1 vector B. I want to insert B into A such that B is in the first position.

I have this:

A <- list(LETTERS, letters)
B <- 1:10

I want this:

A <- list(B, A[[1]], A[[2]])

I currently do this:

B <- list(B)    
for (i in 1:length(A)) {
    B[i+1] <- A[[i]]}

Is there a better way without using for loops?

RJ-
  • 2,919
  • 3
  • 28
  • 35

1 Answers1

2

You can simply use c :

c(list(B), A)
Tutuchan
  • 1,527
  • 10
  • 19