0

I have one list with n datas processed and in each data there are 15 arrays. I have to create one list to each kind of array, like

list1 <- Dados_processados[[1]][[1]], Dados_processados[[2]][[1]], 
   Dados_processados[[3]][[1]]...Dados_processados[[n]][[1]]

here's what the data looks like

enter image description here

I've tried to do this with 'while', but it went wrong.

smci
  • 32,567
  • 20
  • 113
  • 146
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Pictures of data aren't very helpful because we can't copy/paste them to test with. Show the code you tried and describe what "went wrong" exactly. – MrFlick Jun 12 '19 at 19:27
  • Please post an executable snippet of your data, not an image/screenshot. Input: does "list of arrays" mean "list of numpy arrays", "list of Python arrays" or "list of Python lists"? We can't tell from a screenshot. Output: do you want a flattened list? or else what? – smci Jun 12 '19 at 19:33

1 Answers1

0

To make the example smaller, I'll take n to be 3 and each list to be length 5 rather than 15.

l <- list(
  as.list(1:5),
  as.list(11:15),
  as.list(21:25)
)
str(l)
#> List of 3
#>  $ :List of 5
#>   ..$ : int 1
#>   ..$ : int 2
#>   ..$ : int 3
#>   ..$ : int 4
#>   ..$ : int 5
#>  $ :List of 5
#>   ..$ : int 11
#>   ..$ : int 12
#>   ..$ : int 13
#>   ..$ : int 14
#>   ..$ : int 15
#>  $ :List of 5
#>   ..$ : int 21
#>   ..$ : int 22
#>   ..$ : int 23
#>   ..$ : int 24
#>   ..$ : int 25

purrr::transpose will turn the list "inside-out" in the way you describe.

l2 <- purrr::transpose(l)
str(l2)
#> List of 5
#>  $ :List of 3
#>   ..$ : int 1
#>   ..$ : int 11
#>   ..$ : int 21
#>  $ :List of 3
#>   ..$ : int 2
#>   ..$ : int 12
#>   ..$ : int 22
#>  $ :List of 3
#>   ..$ : int 3
#>   ..$ : int 13
#>   ..$ : int 23
#>  $ :List of 3
#>   ..$ : int 4
#>   ..$ : int 14
#>   ..$ : int 24
#>  $ :List of 3
#>   ..$ : int 5
#>   ..$ : int 15
#>   ..$ : int 25
Paul
  • 8,734
  • 1
  • 26
  • 36