在r studio中使用rep命令重命名特定列
我试图将黑猩猩和人类的大脑样本重新命名,将它们组合在一起。总共有24个样本,前12个是黑猩猩,最后一个是人类。它按大脑区域重复3次(4个不同大脑区域的3个不同黑猩猩/人类样本)。我已经能够生成所有24个样本名称,但它们的顺序不正确。它应该是前额叶、尾状叶、小脑、小脑,然后再重复2次,然后对人体样本进行相同的设置。有什么建议吗?这就是我到目前为止所做的:在r studio中使用rep命令重命名特定列,r,R,我试图将黑猩猩和人类的大脑样本重新命名,将它们组合在一起。总共有24个样本,前12个是黑猩猩,最后一个是人类。它按大脑区域重复3次(4个不同大脑区域的3个不同黑猩猩/人类样本)。我已经能够生成所有24个样本名称,但它们的顺序不正确。它应该是前额叶、尾状叶、小脑、小脑,然后再重复2次,然后对人体样本进行相同的设置。有什么建议吗?这就是我到目前为止所做的: trts=paste(rep(c("CHPrefrontal","CHCaudate","CHCerebellum","CHBroca","HU
trts=paste(rep(c("CHPrefrontal","CHCaudate","CHCerebellum","CHBroca","HUPre frontal","HUCaudate","HUCerebellum","HUBroca"),each=3),rep(c(1:3, 1:3, times=3)),sep="")
paste(trts)
输出为:
[1] "CHPrefrontal1" "CHPrefrontal2" "CHPrefrontal3"
[4] "CHCaudate1" "CHCaudate2" "CHCaudate3"
[7] "CHCerebellum3" "CHCerebellum1" "CHCerebellum2"
[10] "CHBroca3" "CHBroca1" "CHBroca2"
[13] "HUPrefrontal3" "HUPrefrontal3" "HUPrefrontal1"
[16] "HUCaudate2" "HUCaudate3" "HUCaudate1"
[19] "HUCerebellum2" "HUCerebellum3" "HUCerebellum3"
[22] "HUBroca1" "HUBroca2" "HUBroca3"
发件人:
我们的职能是:
substrRight来自:
我们的职能是:
substrRight如果不希望附加数字,请尝试:
rep(paste0(rep(c("CH", "HU"), each=3), c("Prefrontal", "Caudate", "Cerebellum", "Broca")), 3)
# [1] "CHPrefrontal" "CHCaudate" "CHCerebellum" "HUBroca" "HUPrefrontal"
# [6] "HUCaudate" "CHPrefrontal" "CHCaudate" "CHCerebellum" "HUBroca"
# [11] "HUPrefrontal" "HUCaudate" "CHPrefrontal" "CHCaudate" "CHCerebellum"
# [16] "HUBroca" "HUPrefrontal" "HUCaudate"
如果不希望附加号码,请尝试:
rep(paste0(rep(c("CH", "HU"), each=3), c("Prefrontal", "Caudate", "Cerebellum", "Broca")), 3)
# [1] "CHPrefrontal" "CHCaudate" "CHCerebellum" "HUBroca" "HUPrefrontal"
# [6] "HUCaudate" "CHPrefrontal" "CHCaudate" "CHCerebellum" "HUBroca"
# [11] "HUPrefrontal" "HUCaudate" "CHPrefrontal" "CHCaudate" "CHCerebellum"
# [16] "HUBroca" "HUPrefrontal" "HUCaudate"
你可以做:
paste0(rep(c("CH", "HU"), each = 12), rep(c("Prefrontal", "Caudate", "Cerebellum", "Broca"), 4))
# [1] "CHPrefrontal" "CHCaudate" "CHCerebellum" "CHBroca" "CHPrefrontal" "CHCaudate"
# [7] "CHCerebellum" "CHBroca" "CHPrefrontal" "CHCaudate" "CHCerebellum" "CHBroca"
# [13] "HUPrefrontal" "HUCaudate" "HUCerebellum" "HUBroca" "HUPrefrontal" "HUCaudate"
# [19] "HUCerebellum" "HUBroca" "HUPrefrontal" "HUCaudate" "HUCerebellum" "HUBroca"
你可以做:
paste0(rep(c("CH", "HU"), each = 12), rep(c("Prefrontal", "Caudate", "Cerebellum", "Broca"), 4))
# [1] "CHPrefrontal" "CHCaudate" "CHCerebellum" "CHBroca" "CHPrefrontal" "CHCaudate"
# [7] "CHCerebellum" "CHBroca" "CHPrefrontal" "CHCaudate" "CHCerebellum" "CHBroca"
# [13] "HUPrefrontal" "HUCaudate" "HUCerebellum" "HUBroca" "HUPrefrontal" "HUCaudate"
# [19] "HUCerebellum" "HUBroca" "HUPrefrontal" "HUCaudate" "HUCerebellum" "HUBroca"
paste0(rep(c(“CH”,“HU”),每个=12),rep(c(“前额”,“尾状”,“小脑”,“布罗卡”),4),rep(rep(rep(1:3,每个=4),2))
对你有用吗?在你的描述中,你的末尾没有附加1、2或3。但在你的代码中你是这样做的。你在找哪一个?我不想要附加的1、2或3。@Alysha:所以像是paste0(rep(c(“CH”、“HU”),每个=12),rep(c(“前额”,“尾状”,“小脑”,“布罗卡”),4))
?是paste0(rep(c(“CH”,“HU”),每个=12),rep(c(“前额”,“尾状”,“小脑”,“布罗卡”),4),rep(rep(rep(1:3,每个=4),2))
为您工作?在您的描述中,您的末尾没有附加1、2或3。但在你的代码中你是这样做的。你在找哪一个?我不想要附加的1、2或3。@Alysha:那么像paste0(rep(c(“CH”、“HU”),每个=12),rep(c(“前额”、“尾状”、“小脑”、“布罗卡”),4))
?