Hi, I am new in R and I have problem with reading this data file 0 TITLE Title 0 XLEGEND Legend -1 LABEL x 1 1 12 1 2 30 1 3 34 I want to read only lines starting with 1 (it indicates 1st plotting line) and create data set from second and third value on this row. Thank for advice Jakub Zlamal -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
My problem is little bit complicate because lines starting 0 or -1 can be everywhere in file (there are also lines starting with 2 or -2, etc...) so structure of file can be 0 something -1 something 1 1 3 2 1 5 -2 something 0 something 1 2 5 1 5 6 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wed, 25 Sep 2002 zlamal at ufi.fme.vutbr.cz wrote: %Hi, I am new in R and I have problem with reading this data file % %0 TITLE Title % 0 XLEGEND Legend %-1 LABEL x %1 1 12 %1 2 30 %1 3 34 % %I want to read only lines starting with 1 (it indicates 1st plotting line) %and create data set from second and third value on this row. what about using read.table(....,skip=3) and later subsetting your dataframe to the two desired columns? % %Thank for advice %Jakub Zlamal %-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- % *********************************************************************** Jens Nieschulze -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
..try help(readLines) !? hope this helps regards,Christian zlamal at ufi.fme.vutbr.cz schrieb am 25.09.02 14:16:06:> Hi, I am new in R and I have problem with reading this data file > > 0 TITLE Title > 0 XLEGEND Legend > -1 LABEL x > 1 1 12 > 1 2 30 > 1 3 34 > > I want to read only lines starting with 1 (it indicates 1st plotting line) > and create data set from second and third value on this row. > > Thank for advice > Jakub Zlamal > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
..i'm sorry, the function scan() should more approriate than readLines(). regards,Christian zlamal at ufi.fme.vutbr.cz schrieb am 25.09.02 14:16:06:> Hi, I am new in R and I have problem with reading this data file > > 0 TITLE Title > 0 XLEGEND Legend > -1 LABEL x > 1 1 12 > 1 2 30 > 1 3 34 > > I want to read only lines starting with 1 (it indicates 1st plotting line) > and create data set from second and third value on this row. > > Thank for advice > Jakub Zlamal > -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- > r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html > Send "info", "help", or "[un]subscribe" > (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch > _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello, If the lines starting with "1" are from the 3rd onwards, you can use read.table(...,skip=3). If not, you can pre-process the file with awk, sed, etc. which are also available for Windows. Regards, Carlos. -----Mensaje original----- De: owner-r-help at stat.math.ethz.ch [mailto:owner-r-help at stat.math.ethz.ch]En nombre de zlamal at ufi.fme.vutbr.cz Enviado el: miercoles, 25 de septiembre de 2002 13:16 Para: r-help at stat.math.ethz.ch Asunto: [R] Reading complicated data file Hi, I am new in R and I have problem with reading this data file 0 TITLE Title 0 XLEGEND Legend -1 LABEL x 1 1 12 1 2 30 1 3 34 I want to read only lines starting with 1 (it indicates 1st plotting line) and create data set from second and third value on this row. Thank for advice Jakub Zlamal -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-. -.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._. _._ _____ The information in this email is confidential and it may not be disclosed or used by anyone other than the addressee. If you are not the intended recipient, any disclosure, copying, distribution or any action taken or omitted is prohibited and may be unlawful. Minorplanet cannot accept responsibility for the accuracy or completeness of this email as it has been transmitted over a public network. If you suspect that the email may have been amended, please call the sender. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Dear Jakub, At 01:15 PM 9/25/2002 +0200, zlamal at ufi.fme.vutbr.cz wrote:>Hi, I am new in R and I have problem with reading this data file > >0 TITLE Title > 0 XLEGEND Legend >-1 LABEL x >1 1 12 >1 2 30 >1 3 34If you know in advance where the data starts (i.e., that you need to skip the first 3 rows), then you can read the data file with read.table in the usual manner, but specifying the argument skip=3. This also supposes that the lines to be skipped precede the data. If the situation is more complicated -- e.g., you don't know in advance how many lines to skip, or the data and non-data lines are intermixed -- then there are several ways to proceed. One way would be to read the data in the usual manner, and then to select rows for which the first column is 1; with this approach, you would also have to handle converting columns two and three to numeric. Alternatively, you could read the file line-by-line (see ?readLines). I hope that this helps, John ----------------------------------------------------- John Fox Department of Sociology McMaster University Hamilton, Ontario, Canada L8S 4M4 email: jfox at mcmaster.ca phone: 905-525-9140x23604 web: www.socsci.mcmaster.ca/jfox ----------------------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Something like tmpdat <- scan('filename',what=list(id=0,col1='',col2='')) use <- tmpdat$id==1 dat <- data.frame(x=as.numeric(tmpdat$col1[use]), y=as.numeric(tmpdat$col2[use]) should get you a dataframe with two columns corresponding to the second and third values from each row. (caveat: I haven't tested it. Check the documentation for scan regarding delimiters. Also, I'm assuming every row in your data is complete, with exactly three values.) -Don At 1:15 PM +0200 9/25/02, zlamal at ufi.fme.vutbr.cz wrote:>Hi, I am new in R and I have problem with reading this data file > >0 TITLE Title > 0 XLEGEND Legend >-1 LABEL x >1 1 12 >1 2 30 >1 3 34 > >I want to read only lines starting with 1 (it indicates 1st plotting line) >and create data set from second and third value on this row. > >Thank for advice >Jakub Zlamal >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- >r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html >Send "info", "help", or "[un]subscribe" >(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA -------------------------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
You can read the file in as a character vector, 'grep' the ones you want and then use 'textConnection'; e.g.,> x.1 <- scan('/tempxx.txt', what='', sep='\n') # read file with '\n' asseparator Read 6 items> x.1[1] "0 TITLE Title" " 0 XLEGEND Legend" "-1 LABEL x" [4] "1 1 12" "1 2 30" "1 3 34"> x.match <- x.1[grep("^1", x.1)] # match on leading '1' > x.match[1] "1 1 12" "1 2 30" "1 3 34"> x.data <- read.table(textConnection(x.match)) # use textConnection to'read' in the data> x.dataV1 V2 V3 1 1 1 12 2 1 2 30 3 1 3 34 At 1:15 PM +0200 9/25/02, zlamal at ufi.fme.vutbr.cz wrote:>Hi, I am new in R and I have problem with reading this data file > >0 TITLE Title > 0 XLEGEND Legend >-1 LABEL x >1 1 12 >1 2 30 >1 3 34 > >I want to read only lines starting with 1 (it indicates 1st plotting line) >and create data set from second and third value on this row. > >Thank for advice >Jakub Zlamal >-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.->r-help mailing list -- Readhttp://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html>Send "info", "help", or "[un]subscribe" >(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch >_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ -- "NOTICE: The information contained in this electronic mail transmission is intended by Convergys Corporation for the use of the named individual or entity to which it is directed and may contain information that is privileged or otherwise confidential. If you have received this electronic mail transmission in error, please delete it from your system without copying or forwarding it, and notify the sender of the error by reply email or by telephone (collect), so that the sender's address records can be corrected." -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Wednesday 25 September 2002 07:15 am, zlamal at ufi.fme.vutbr.cz wrote:> Hi, I am new in R and I have problem with reading this data file > > 0 TITLE Title > 0 XLEGEND Legend > -1 LABEL x > 1 1 12 > 1 2 30 > 1 3 34 > > I want to read only lines starting with 1 (it indicates 1st plotting line) > and create data set from second and third value on this row. > > Thank for advice > Jakub ZlamalIs it practical for you to filter the file, e.g. with a perl script? #!/usr/bin/perl -w $file = shift; open IN, $file or die $!; while (<IN>) { print if /^1/; } Cheers, Jim -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello, I defined a function funy to get means(sd)n for groups in a dataframe funy<-function(x) list(mean(x,na.rm=T),sd(x,na.rm=T),table(is.na(x))[1]) aa<-tapply(y,list(g1,g2,g3),funy) typing aa gives , , G.Baie Admin CBNE Coulee Electr ExCuv Fluo ExpAnt Non List,3 List,3 List,3 List,3 NULL NULL NULL Ex List,3 List,3 List,3 List,3 NULL NULL NULL Curr List,3 List,3 List,3 List,3 NULL NULL NULL , , Later Admin CBNE Coulee Electr ExCuv Fluo ExpAnt Non List,3 List,3 List,3 List,3 List,3 List,3 List,3 Ex List,3 List,3 List,3 List,3 List,3 List,3 List,3 Curr List,3 List,3 List,3 List,3 List,3 NULL List,3 , , Shawi Admin CBNE Coulee Electr ExCuv Fluo ExpAnt Non List,3 List,3 List,3 List,3 List,3 NULL List,3 Ex List,3 List,3 List,3 List,3 List,3 NULL List,3 Curr List,3 List,3 List,3 List,3 List,3 NULL List,3 but I want the componenets of the lists, so I do bb<-matrix(unlist(aa),nrow=3) now typing bb gives me [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,] 104.10811 103.363636 101.90909 102.02439 104.10000 97.69149 98.56522 [2,] 11.34995 9.564545 13.52372 14.40420 11.88250 13.63820 12.12370 [3,] 37.00000 22.000000 11.00000 82.00000 50.00000 94.00000 23.00000 [,8] [,9] [,10] [,11] [,12] [,13] [,14] [,15] [1,] 98.31250 99.24138 99.96250 100.49020 97.27586 102.82759 107.33333 97.15385 [2,] 15.36975 9.25687 11.94761 13.93897 12.77870 12.53301 10.03026 14.12354 [3,] 16.00000 29.00000 80.00000 51.00000 87.00000 29.00000 12.00000 13.00000 [,16] [,17] [,18] [,19] [,20] [,21] [,22] [1,] 101.00000 97.85000 94.00000 96.333333 102.21429 95.50000 100.18033 [2,] 11.48291 14.70866 18.64806 9.232448 13.31961 15.88325 12.38616 [3,] 15.00000 20.00000 17.00000 15.000000 14.00000 10.00000 61.00000 i.e. the NULL lists are bypassed and I lose all relationship with the levels of the by variables Is there a way to have lists of 3 NA's in the place of the NULL lists As always many thanks for any help. -- R. Heberto Ghezzo Ph.D. Meakins-Christie Labs McGill University Montreal - Canada -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._