0

I have these object (I have thousands of [[i]], this is just an example):

v

[[1]] 1 2 3 4

[[2]] 5 6 7 8

I want to create a new vector (column) like this:

vector
1
2
3
4
5
6
7
8

,using a for loop. I tried this but it doesn't work:

vector=c()
for(i in 1:2){
    vector[i]=v[[i]]
}
doctorlove
  • 18,872
  • 2
  • 46
  • 62
Ari
  • 11
  • 4

1 Answers1

0

It seems that the input data is a list. So we need to unlist it

v1 <- unlist(v)
v1
#[1] 1 2 3 4 5 6 7 8

If we need a for loop

v2 <- c()
for(i in seq_along(v)) v2 <- c(v2, v[[i]])

data

v <- list(1:4, 5:8)
akrun
  • 874,273
  • 37
  • 540
  • 662