Reputation: 105
I have a list of 322 vectors with this format:
...
[[320]]
[1] 0 0 0 0 0 0 0 40 0 32 20 8 25 0 35
[[321]]
[1] 0 0 0 0 0 0 0 0 35 32 20 13 25 40 0
[[322]]
[1] 0 0 0 0 0 0 0 0 0 32 20 48 25 40 35
To here is simple, 322 vectors of 15 numbers each one, so i want to make something like this:
factlist<-factlist[,1:8]
#Output:
...
[[320]]
[1] 0 0 0 0 0 0 0 40
[[321]]
[1] 0 0 0 0 0 0 0 0
[[322]]
[1] 0 0 0 0 0 0 0 0
What I want to make is to cut the elements from 8 to 15 leaving the rest but i don't know how to do this with this list format, thanks.
Upvotes: 2
Views: 31
Reputation: 887961
We can use lapply
to loop over the list
, then with head
get the first 8 elements
lapply(factlist, head, n = 8)
Or using :
lapply(factlist, function(x) x[1:8])
Upvotes: 1