我有一个从PCR板软件导出的文件。我需要一个代码来将调用变量(“等位基因1,等位基因2,杂合子和无应答”)转换为两个单独的变量(“ G1-2 1”和“ G1-2 2”)
定义
没有电话为空
等位基因1是+ / +
等位基因2为G11384M / G11384M(如果在R中可能,则为上标)
杂合子为G11384M / +
任何帮助/指导将不胜感激
原始文件导出
我需要什么
数据str
Classes ‘tbl_df’, ‘tbl’ and 'data.frame': 96 obs. of 2 variables:
$ Well: chr "A01" "A02" "A03" "A04" ...
$ Call: chr "No Call" "No Call" "Allele 1" "Allele 1" ...
答案 0 :(得分:1)
这就是我要做的:
data = data.frame(
Well = c("A01", "A02", "A03", "A04", "A05", "A06", "A07", "A08"),
Call = c("No Call", "No Call", "Allele 1", "Heterozygote", "Allele 1",
"Allele 2", "Heterozygote", "Heterozygote"),
stringsAsFactors=FALSE
)
g121map = c("No Call"="", "Allele 1"="+", "Allele 2"="G1^{1384M}",
"Heterozygote"="G1^{1384M}")
g122map = c("No Call"="", "Allele 1"="+", "Allele 2"="G1^{1384M}",
"Heterozygote"="+")
data["G1-21"] = g121map[data$Call]
data["G1-22"] = g122map[data$Call]
数据框现在看起来像这样:
> data
Well Call G1-21 G1-22
1 A01 No Call
2 A02 No Call
3 A03 Allele 1 + +
4 A04 Heterozygote G1^{1384M} +
5 A05 Allele 1 + +
6 A06 Allele 2 G1^{1384M} G1^{1384M}
7 A07 Heterozygote G1^{1384M} +
8 A08 Heterozygote G1^{1384M} +
您可以在绘图中使用指数格式。