looping problem
Thanks so much for this. Unfortunately, cbind did not work. Basically, I like to put an extra column named "chr" in the combined file from 22 chr. So chr colum will be "1" for the portion of chr1 in the combined file, 2 for the portion of chr2 in the combined file and so on. Regards, Greg
On Thu, Feb 2, 2017 at 9:39 AM, Rui Barradas <ruipbarradas at sapo.pt> wrote:
Hello, If I understand correctly, just use ?cbind. Rui Barradas Em 02-02-2017 13:33, greg holly escreveu:
Hi Rui;
Is there any way to insert the chr ids in numeric as 1,2......,22 in the
final output. Here is output from str(temp). So I need also chr ids in a
column.
1 rs58108140 10583 G A -0.070438 0.059903
2 rs189107123 10611 C G -0.044916 0.085853
Regards,
Greg
On Wed, Feb 1, 2017 at 1:32 PM, Rui Barradas <ruipbarradas at sapo.pt
<mailto:ruipbarradas at sapo.pt>> wrote:
Hello,
If what you want is to combine the files into one data.frame then
there are 2 things you should see:
1) You create a variable named 'temp' and don't ever use it.
2) You never combine the data.frames you read in.
Try instead the following.
temp <- data.frame()
for(i in 1:22) {
infile<-paste("chr",i,"/Z-score.imputed",sep="")
psT<-read.table(infile,header=T,as.is <http://as.is>=T,sep="\t")
temp <- rbind(temp, psT)
}
str(temp) # to see what you have
Hope this helps,
Rui Barradas
Em 01-02-2017 17:25, greg holly escreveu:
Hi all;
I have 22 directories named chr1, chr2,....,chr22. Each
directory has a
file named "Z-score.imputed". I would like to combine
Z-score.imputed
files into one. I wrote the following loop but did not get any
results.
Your helps are highly appreciated.
regards,
Greg
temp<-c()
for(i in 1:22) {
infile<-paste("chr",i,"/Z-score.imputed",sep="")
psT<-read.table(as.character(infile),header=T,as.is
<http://as.is>=T,sep="\t")
ps<-psT[psT$Var>0.6,]
ratio=nrow(ps)/nrow(psT)
print(ratio)
}
[[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org <mailto:R-help at r-project.org> mailing list
-- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
<https://stat.ethz.ch/mailman/listinfo/r-help>
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
<http://www.R-project.org/posting-guide.html>
and provide commented, minimal, self-contained, reproducible code.