user2359494
user2359494

Reputation: 733

Modifying list length in R

A procedure I'm running in R generates the following list for me:

[[1]]
[1] 280.9391

[[2]]
[1] 36.54459

[[3]]
[1] 51.71247

[[4]]
[1] 287.1063

[[5]]
[1] 45.17028

[[6]]
[1] 35.16948

[[7]]
[1] 274.397

[[8]]
[1] 62.25498

[[9]]
[1] 33.58602

[[10]]
[1] 242.2277

[[11]]
[1] 41.12829

[[12]]
[1] 74.42262

[[13]]
[1] 259.5208

[[14]]
[1] 165.8883

[[15]]
[1] 56.75454

[[16]]
[1] 272.4801

[[17]]
[1] 68.79717

[[18]]
[1] 49.54563

[[19]]
[1] 285.2728

[[20]]
[1] 44.96193

[[21]]
[1] 49.5873

[[22]]
[1] 267.3547

[[23]]
[1] 150.1787

[[24]]
[1] 66.00528

[[25]]
[1] 278.7723

[[26]]
[1] 62.21331

[[27]]
[1] 82.04823

[[28]]
[1] 274.3136

[[29]]
[1] 51.92082

[[30]]
[1] 64.21347

I'd like the length of the list to be 3 rather than 30, with every value being in one of the 3 categories. For example, the first value [[1]] would be in the first category, [[2]] would be the second, [[3]] would be the third, [[4]] would be the first, [[5]] would be second, [[6]] would be the third, and so on. Each of the three categories would then have 10 values associated with them. I'm having a hard time figuring out how to do that and I was wondering if someone could help. Thanks in advance.

--Neil

Upvotes: 2

Views: 197

Answers (1)

flodel
flodel

Reputation: 89057

Try this:

split(unlist(ll), (seq_along(ll) - 1L) %% 3L)

where ll is your list.

Upvotes: 3

Related Questions