【发布时间】:2013-12-11 19:07:03
【问题描述】:
我想转换这些数据:
Sample Genotype Region
sample1 A Region1
sample1 B Region1
sample1 A Region1
sample2 A Region1
sample2 A Region1
sample3 A Region1
sample4 B Region1
在该格式中,用“E”标记具有多个基因型的样本并将具有相同基因型的样本统一2次:
Sample Genotype Region
sample1 E Region1
sample2 A Region1
sample3 A Region1
sample4 B Region1
我有一个包含多个区域的列表(Region1 - Regionx)。可以在R软件中做吗?非常感谢。
【问题讨论】:
-
许多选项:来自 plyr 包的
tapply或ddply或data.table包 -
我想在统一行中将“基因型”列中的排除 (E) 标记为具有多个基因型的样本 (sample1),并将行统一到具有两行重复基因型的样本 (sample2)
-
是data.frame,单列是因子还是带字符串的矩阵?这种分析是按地区进行的吗?或者它们是如何总结的。对于基因型,您可以使用
function(x) ifelse(length(unique(x))==1,x[1],'E')