我有一个染色体名称向量
q<-c("1","10","11","12","13","14","15","16","17",
"18","19","20","21","22","2","3","4","5","6",
"7","8","9","X","Y","M")
我想将它们排序为
q<-c("1","2","3","4","5","6","7","8","9","10","11",
"12","13","14","15","16","17","18","19","20",
"21","22","X","Y","M")
我试着自己下订单
chrOrder <-c((1:22),"X","Y","M")
并像使用它一样
factor(cbind(q),levels=chrOrder)
但我仍然无法得到它。
已编辑.....我有类似的情况,但有点先进。我有一个三列的数据框,名称,染色体,开始
df <-data.frame(name =c("a","a","a","b","b","b"), chrom = c(1,2,10,1,3,"X"), start=c(100,200,300,500,300,200))
我需要先按名称排序,然后是染色体和开头。结果应该是这样的
name chrom start
a 1 100
a 10 300
a 2 200
b 1 500
b 3 300
b X 200
我不知道如何在以下使用 chrOrder:
indata <- df[do.call(order,df[,c(name, chrom, start)]),];