从文本和序列编号中创建一个带有Rownames paste0的新数据框
hej,
这可能以前已经对此进行了审查,加上我的R技能正在变得生锈,但我正在尝试生成一个新的数据框架,其中将从两个列数据框架中从字符串和效果 /序列编号中生成Rownames。
为了更有意义,我的数据框看起来像:
IND Effect
A 3
B 2
C 4
read.table(text = "IND Effect
A 3
B 2
C 4", h = T)
我想要
IND
A_1
A_2
A_3
B_1
B_2
C_1
C_2
C_3
C_4
在新的数据框架上类似的东西。我尝试了:
new = mapply(function(x, y) paste0(rep(x, y), collapse = "_"), IND , Effect)
但是不按照我的意愿工作。
Hej,
This might have been reviewed before, plus my R skills are getting rusty, but I am trying to generate a new dataframe, where rownames will be generated from strings and effectif / sequence number from a two columns data frame.
To make more sense I have a dataframe looking like :
IND Effect
A 3
B 2
C 4
read.table(text = "IND Effect
A 3
B 2
C 4", h = T)
And I want something like
IND
A_1
A_2
A_3
B_1
B_2
C_1
C_2
C_3
C_4
on a new data frame. I tryed :
new = mapply(function(x, y) paste0(rep(x, y), collapse = "_"), IND , Effect)
but doesn't work as I would like....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在
seq_len()
函数的帮助下:You may nee the help of the
seq_len()
function:使用
mapply
:输出
数据
with
mapply
:output
data