[R] Read text file in R

arun smartpink111 at yahoo.com
Mon Mar 25 18:32:30 CET 2013



res[res$EN==min(res$EN),]
#   m1 n1  m  n cterm1_P0L cterm1_P0H  c11  c12   c1   c2 alpha beta   T_error
#25  9  4 13 12  0.6302494  0.7565041 0.03 0.07 0.15 0.15   0.1  0.2 0.4403712
#27  9  4 13 12  0.6302494  0.7565041 0.03 0.07 0.15 0.20   0.1  0.2 0.4473437
#33  9  4 13 12  0.6302494  0.7565041 0.05 0.07 0.15 0.15   0.1  0.2 0.4403712
#35  9  4 13 12  0.6302494  0.7565041 0.05 0.07 0.15 0.20   0.1  0.2 0.4473437
    N       EN        BH        BL         AH         AL
#25 25 16.42697 0.1201138 0.1933632 0.09321455 0.03367957
#27 25 16.42697 0.1553998 0.1933632 0.06490110 0.03367957
#33 25 16.42697 0.1201138 0.1933632 0.09321455 0.03367957
#35 25 16.42697 0.1553998 0.1933632 0.06490110 0.03367957
A.K.



________________________________
From: Joanna Zhang <zjoanna2013 at gmail.com>
To: arun <smartpink111 at yahoo.com> 
Sent: Monday, March 25, 2013 12:13 PM
Subject: Re: Read text file in R


Great! When I tried to extract the min of EN, it has an error;



opt<-con[con$EN==min(con$EN),]
opt
Error in con$EN : $ operator is invalid for atomic vectors




On Mon, Mar 25, 2013 at 11:05 AM, arun <smartpink111 at yahoo.com> wrote:

Hi,
>Try this:
>con<-file("Routallnew.txt")
> Lines1<- readLines(con)
> close(con)
>indx<-rep(rep(c(TRUE,FALSE),each=2),24)
>Lines2<-Lines1[!grepl("[A-Za-z]",Lines1)]
>res<-read.table(text=paste(gsub("^\\s+","",Lines2[indx]),gsub("^\\s+","",Lines2[!indx])),sep="",header=FALSE)
>nm1<-unlist(strsplit(gsub("^ +","",paste(Lines1[grepl("[A-Za-z]",Lines1)][1:2],collapse=" "))," "))
>colnames(res)<- nm1[nm1!=""]
>head(res)
>#  m1 n1  m  n cterm1_P0L cterm1_P0H  c11  c12   c1   c2 alpha beta   T_error  N
>#1 13  5 17  9  0.7851203  0.6689925 0.03 0.03 0.15 0.15   0.1  0.2 0.3669373 26
>#2 13  5 17  9  0.7851203  0.6689925 0.03 0.03 0.15 0.15   0.1  0.2 0.3669373 26
>#3  9  5 13 11  0.6302494  0.4876750 0.03 0.03 0.15 0.20   0.1  0.2 0.4137296 24
>#4  9  5 13 11  0.6302494  0.4876750 0.03 0.03 0.15 0.20   0.1  0.2 0.4137296 24
>#5  9  5 13 11  0.6302494  0.4876750 0.03 0.03 0.15 0.25   0.1  0.2 0.4782406 24
>#6  9  5 13 11  0.6302494  0.4876750 0.03 0.03 0.15 0.25   0.1  0.2 0.4782406 24
>#        EN         BH        BL         AH         AL
>#1 20.18355 0.07718537 0.1865207 0.08079875 0.02243240
>#2 20.18355 0.07718537 0.1865207 0.08079875 0.02243240
>#3 18.55295 0.08482219 0.1996013 0.09569044 0.03361565
>#4 18.55295 0.08482219 0.1996013 0.09569044 0.03361565
>#5 18.55295 0.19596330 0.1996013 0.04906038 0.03361565
>#6 18.55295 0.19596330 0.1996013 0.04906038 0.03361565
>
>A.K.
>
>
>
>
>
>
>________________________________
>From: Joanna Zhang <zjoanna2013 at gmail.com>
>To: arun <smartpink111 at yahoo.com>
>Sent: Monday, March 25, 2013 11:19 AM
>Subject: Read text file in R
>
>
>
>Hi Arun,
>
>I just sent  you a text file via R, but I think it is being held for moderator approval. I attached the final output file here, could you help me read it in R when you have time?
>



More information about the R-help mailing list