有一个很大的文件,想要随机抽取其中的200行。
在服务器上运行R语言:
R
rd<-read.table("test.fam")
sub<-sample(nrow(rd),6000)
rdnew<-rd[sub,]
write.table(rdnew,"new.txt",quote = FALSE,row.names = FALSE,col.names = FALSE)
合并两个不一样长,但是含有相同列的文件。其实也就是通过一个文件的某一列索引另一个文件,找到对应的内容。用R很方便
R
rd<-read.table("1-Stoort.fam")
phe<-read.table("pheno.txt")
mer<-merge(rd,phe,by="V1") #这一列其实是id
mer<-mer[,c(-6,-7)] #删除重复
write.table(mer,"mer.txt",quote = FALSE,row.names = FALSE,col.names = FALSE)
运行R脚本
R.script ____.R
网友评论