我有以下列表,请说:
> a
[[1]]
[1] "C" "A" "C" "C" "U" "U" "G" "U" "C" "C" "U" "C" "A" "C" "G" "G" "U" "C"
[[2]]
[1] "G" "U" "A" "G" "C" "A" "C" "U" "A" "A" "A" "G" "U" "G" "C" "U" "U" "A"
我还有其他数字列表,它们对应于我想从a中提取的位置索引,比如b:
> b
[[1]]
[1] 3 4 6 7 9 10 11 12
[[2]]
[1] 1 2 3 4 6 7 8 10
我想提取每个字母的索引位置对应于列表b中的向量,比如说,输出会是这样的:
> c
[[1]]
[1] "C" "C" "U" "G" "C" "C" "U" "C"
[[2]]
[1] "G" "U" "A" "G" "A" "C" "U" "A"
我知道如何从列表中的每个向量中提取一个元素,比方说,我想从列表a中提取每个第一个元素(索引1),所以我将应用下一个代码:
lapply(a, '[[', 1)
但是我怎样才能提取多个值?如果在最后一个代码中使用put b而不是“1”,我会收到错误...
Error in FUN(X[[i]], ...) :
attempt to select more than one element in vectorIndex
我应该使用for循环吗?
答案 0 :(得分:3)
您可以尝试:
mapply(function(x,y) x[y], a, b)
答案 1 :(得分:1)
这是一种将数据转换为表格格式的方法:
document.querySelectorAll('#here_we_go>div>img')