染色体名のベクトルがあります
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)
しかし、それでも私はそれを得ることができませんでした。
編集..... 私は同様のシナリオを持っていますが、少し進んでいます。名前、染色体、開始の 3 つの列のデータ フレームがあります。
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)]),];