其中每个代表一个向量的rep()
我有一个关于序列和each
的快速问题:
vect1 <- c(4, 5, 10, 3, 1)
我想用这个向量进行复制,使得第一个数字被复制为4,第二个数字为5,第三个数字为10,第四个数字为3,第五个数字等于1。
rep(1:5, each = vect1)
[1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5
Warning message:
In rep(1:5, each = vect1) : first element used of 'each' argument
rep(1:5, each = c(4, 5, 10, 3, 1))
[1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5
Warning message:
In rep(1:5, each = c(4, 5, 10, 3, 1)) :
first element used of 'each' argument
我知道这是滥用每一个。
I have quick question regarding sequence and each
:
vect1 <- c(4, 5, 10, 3, 1)
I want replicate with this vector as each such that first number is replicated 4, second 5, third 10, fourth 3, and fifth equal 1.
rep(1:5, each = vect1)
[1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5
Warning message:
In rep(1:5, each = vect1) : first element used of 'each' argument
rep(1:5, each = c(4, 5, 10, 3, 1))
[1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5
Warning message:
In rep(1:5, each = c(4, 5, 10, 3, 1)) :
first element used of 'each' argument
I know this is misuse of each.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您对如何在 R 中使用函数有疑问,请尝试
其中“函数”是您想了解的任何函数。从
?rep
你会读到:If you have questions about how to work functions in R, try
where "function" is whatever function you want to know about. From
?rep
you would have read: