Hi I got a file that looks like this: (i have shorten it alot the real file is over 200k rows long)
chr10 rs7909677 101955 A G 0 1 0 1 0 0... chr10 rs2436025 238506 C G 1 0 0 1 0 0... chr10 rs11253562 148946 C T 0 1 0 0 1 ... chr10 rs1105116 230788 G T 0 0 1 0 0 1... chr10 rs4881551 149076 A G 0 1 0 0 1 0 0 1... What I want it to go trough the file and get the highest value in the third column so to say. And because the file is so big I don't want to read it all into the memory so reading in chunks and then traverse it line by line and get the biggest number. What I've experiment with is something like this inFile <- file('gwas_data_chr10.gen') output <- 0 while(length(input <- readLines(inFile, n=1000)) > 0){ for (i in seq_along(input)){ temp<-as.numeric(strsplit(input[i], " +")[[1]][3]) if(output<temp){ output<-temp } } } close(inFile) The problem is that it seems to get stuck on an infinity loop of the 1000 first rows of the file, it dossent continue with the next 1000 from the first loop so to say. Can someone see the error in my code or dose anyone have an other solution to the problem? -- View this message in context: http://r.789695.n4.nabble.com/Read-file-line-by-line-tp3602349p3602349.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.