gpt4 book ai didi

arrays - R 将值插入数组

转载 作者:行者123 更新时间:2023-12-02 06:34:48 26 4
gpt4 key购买 nike

如何转换 A

A <- c(1,2,3,4,5,6,7,8,9)

到B

B <- c(0,0,1,2,3,0,0,4,5,6,0,0,7,8,9)

我尝试过这个:

A <-c(1,2,3,4,5,6,7,8,9)
rows <- length(A)/3
dim(a) <- c(rows,3)
B <- matrix(0,rows,2+3)
B[,3:5] <- A

c(B)

但它不起作用。

最佳答案

为什么不用A来变换B:

b <- rep(c(0,0,1,1,1),time=length(A)/3)
b[b==1] <- A
b
[1] 0 0 1 2 3 0 0 4 5 6 0 0 7 8 9

关于arrays - R 将值插入数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13903568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com