[英]How can I select columns from a vectors list?
I have a list of 322 vectors with this format:我有一个具有这种格式的 322 个向量的列表:
...
[[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:到这里很简单,每个 15 个数字的 322 个向量,所以我想做这样的事情:
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.我想做的是将元素从 8 个减少到 15 个,留下 rest 但我不知道如何使用此列表格式执行此操作,谢谢。
We can use lapply
to loop over the list
, then with head
get the first 8 elements我们可以使用lapply
循环遍历list
,然后使用head
获取前 8 个元素
lapply(factlist, head, n = 8)
Or using :
或使用:
lapply(factlist, function(x) x[1:8])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.