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.
Q <- c(1,2,3,4)
我想让它使向量中的每个值都乘以它的向量编号。这样1*1, 2*2, 3*3, 4*4
1*1, 2*2, 3*3, 4*4
尝试:
Q * seq_along(Q) #[1] 1 4 9 16
一种方法是:
>Q*1:length(Q) #[1] 1 4 9 16