Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想写一个函数,给定一个列表 L,它的每个组件都是一个向量,返回一个整数向量 V,这样对于每个 i,V[i] 是 L[[i]] 的长度
使用 sapply:
sapply(L, length)
例如:
L = list(c(1, 2, 3), c(2, 3), c(3, 4, 5, 6)) sapply(L, length) # [1] 3 2 4