[R] problem with read.table
Dear all, I try to use read.table to get the data from a tab delimited file, and some of the data is shown below: 3185heterogeneous nuclear ribonucleoprotein F 3187heterogeneous nuclear ribonucleoprotein H1 (H) 3188heterogeneous nuclear ribonucleoprotein H2 (H') 3189heterogeneous nuclear ribonucleoprotein H3 (2H9) 3190heterogeneous nuclear ribonucleoprotein K /// heterogeneous nuclear ribonucleoprotein K 3190heterogeneous nuclear ribonucleoprotein K 3309heat shock 70kDa protein 5 (glucose-regulated protein, 78kDa) 3310heat shock 70kDa protein 6 (HSP70B') 3312heat shock 70kDa protein 8 3313heat shock 70kDa protein 9B (mortalin-2) 6302sarcoma amplified sequence 6303spermidine/spermine N1-acetyltransferase 6304special AT-rich sequence binding protein 1 (binds to nuclear matrix/scaffold-associating DNA's) 6305SET binding factor 1 6307sterol-C4-methyl oxidase-like 6625Small nuclear ribonucleoprotein 70kDa polypeptide (RNP antigen) 6626small nuclear ribonucleoprotein polypeptide A 6627small nuclear ribonucleoprotein polypeptide A' 6628small nuclear ribonucleoprotein polypeptides B and B1 6629Small nuclear ribonucleoprotein polypeptide B'' when I use test - read.table(data.txt, colClasses = character, sep=\t) I found out that test only has certain records: 3185heterogeneous nuclear ribonucleoprotein F 3187heterogeneous nuclear ribonucleoprotein H1 (H) 3188heterogeneous nuclear ribonucleoprotein H2 (H') 3312heat shock 70kDa protein 8 3313heat shock 70kDa protein 9B (mortalin-2) 6302sarcoma amplified sequence 6303spermidine/spermine N1-acetyltransferase 6304special AT-rich sequence binding protein 1 (binds to nuclear matrix/scaffold-associating DNA's) 6628small nuclear ribonucleoprotein polypeptides B and B1 6629Small nuclear ribonucleoprotein polypeptide B'' and it means that whenever read.table reads ' , it skips the next line, until it reads ' again Could anyone show me how to solve this kind of problem ? I greatly appreciate for any suggestion. Thanks. Alex Tsoi- [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.
Re: [R] problem with read.table
use quote= to disable the effect of ' cheers Ben Bolker __ R-help@stat.math.ethz.ch 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.
Re: [R] problem with read.table
On May 22, 2007, at 9:41 PM, Alex Tsoi wrote: Dear all, I try to use read.table to get the data from a tab delimited file, and some of the data is shown below: [snip] and it means that whenever read.table reads ' , it skips the next line, until it reads ' again Could anyone show me how to solve this kind of problem ? I greatly appreciate for any suggestion. Thanks. You might want to have a look at ?read.table for more details, but the following should do it: test - read.table(data.txt, colClasses = character, sep=\t, quote=\) Essentially by default read.table sees both and ' as quote delimiters. In your data, you only want as a quote delimiter. Alex Tsoi- Haris Skiadas Department of Mathematics and Computer Science Hanover College __ R-help@stat.math.ethz.ch 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.
[R] problem with read.table( )
Hi All, I would like to input a .txt file by using read.table() the file data.txt: NameID IMAGE:131suid=115221 IMAGE:100020851265 IMAGE:100033464770 IMAGE:1000365suid=99969 IMAGE:100050055421 IMAGE:100087564770 IMAGE:1000892399655 IMAGE:1000942suid=112379 IMAGE:10071415001 IMAGE:100715055 IMAGE:1007164suid=117508 IMAGE:1007167suid=102504 when I use data - read.table(data.txt, sep=\t, header = TRUE) data Name ID 1 IMAGE:131 suid=115221 2 IMAGE:1000208 51265 3 IMAGE:1000334 64770 4 IMAGE:1000365 suid=99969 5 IMAGE:1000500 55421 6 IMAGE:1000875 64770 7 IMAGE:1000892 399655 8 IMAGE:1000942 suid=112379 9 IMAGE:10071415001 10 IMAGE:1007150 55 11 IMAGE:1007164 suid=117508 12 IMAGE:1007167 suid=102504 it seems perfectly fine, however, when I get access to data[1,1] ... data[1,1] [1] IMAGE:131 12 Levels: IMAGE:131 IMAGE:1000208 IMAGE:1000334 ... IMAGE:1007167 How could I get rid of all the Levels in ALL of the entries. It bothers me since when I have to assign certain values from data to a new matrix b by: b - matrix(0,1,2) b[1,1] - data[1,1] b[1,1] 1 b[1,1] is 1 instead of the value IMAGE:131 I want Greatly Appreciate for any help Thanks, Alex- [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.
Re: [R] problem with read.table( )
try: data - read.table(data.txt, sep=\t, header = TRUE, as.is=TRUE) On 5/10/07, Alex Tsoi [EMAIL PROTECTED] wrote: Hi All, I would like to input a .txt file by using read.table() the file data.txt: NameID IMAGE:131suid=115221 IMAGE:100020851265 IMAGE:100033464770 IMAGE:1000365suid=99969 IMAGE:100050055421 IMAGE:100087564770 IMAGE:1000892399655 IMAGE:1000942suid=112379 IMAGE:10071415001 IMAGE:100715055 IMAGE:1007164suid=117508 IMAGE:1007167suid=102504 when I use data - read.table(data.txt, sep=\t, header = TRUE) data Name ID 1 IMAGE:131 suid=115221 2 IMAGE:1000208 51265 3 IMAGE:1000334 64770 4 IMAGE:1000365 suid=99969 5 IMAGE:1000500 55421 6 IMAGE:1000875 64770 7 IMAGE:1000892 399655 8 IMAGE:1000942 suid=112379 9 IMAGE:10071415001 10 IMAGE:1007150 55 11 IMAGE:1007164 suid=117508 12 IMAGE:1007167 suid=102504 it seems perfectly fine, however, when I get access to data[1,1] ... data[1,1] [1] IMAGE:131 12 Levels: IMAGE:131 IMAGE:1000208 IMAGE:1000334 ... IMAGE:1007167 How could I get rid of all the Levels in ALL of the entries. It bothers me since when I have to assign certain values from data to a new matrix b by: b - matrix(0,1,2) b[1,1] - data[1,1] b[1,1] 1 b[1,1] is 1 instead of the value IMAGE:131 I want Greatly Appreciate for any help Thanks, Alex- [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch 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.
[R] problem with read.table
Hi All recently i faced an unknown problem while reading the data. Can someone help me in understanding why this happened. I have .txt file containing X, Y, Z variables. I used the command a - read.table(filename, header=TRUE) after reading the file i am able to view it by tryping a. but i am unable to access the variables in a, by giving the command a$X. a$X NULL this is the output it was showing. However the same i am able to access by giving a[[1]]. i tried changing the mode by issuing command a - as.data.frame(a). But situation remains the same. look forward for experts suggestion on this. rgds snvk __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
Hi All recently i faced an unknown problem while reading the data. Can someone help me in understanding why this happened. I have .txt file containing X, Y, Z variables. I used the command Please show at least 2 lines of your data. a - read.table(filename, header=TRUE) Are you sure, that a looks correct? (= have you set the correct seperator in read.table with option sep= ) Best regards, Matthias after reading the file i am able to view it by tryping a. but i am unable to access the variables in a, by giving the command a$X. a$X NULL this is the output it was showing. However the same i am able to access by giving a[[1]]. i tried changing the mode by issuing command a - as.data.frame(a). But situation remains the same. look forward for experts suggestion on this. rgds snvk __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
Hi Mr. Pedro I tried names(a) and it displayed the names as X, Y and Z. rgds snvk On 8/25/05, Pedro J. Aphalo [EMAIL PROTECTED] wrote: Hi, Did you try names(a) so see what are the names of the columns in the dataframe? Hope this helps a little. Pedro. Krishna wrote: Hi All recently i faced an unknown problem while reading the data. Can someone help me in understanding why this happened. I have .txt file containing X, Y, Z variables. I used the command a - read.table(filename, header=TRUE) after reading the file i am able to view it by tryping a. but i am unable to access the variables in a, by giving the command a$X. a$X NULL this is the output it was showing. However the same i am able to access by giving a[[1]]. i tried changing the mode by issuing command a - as.data.frame(a). But situation remains the same. look forward for experts suggestion on this. rgds snvk __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- == Pedro J. Aphalo Department of Biological and Environmental Science University of Jyväskylä P.O. Box 35, 40351 JYVÄSKYLÄ, Finland Phone +358 14 260 2339 Mobile +358 50 3721504 Fax+358 14 260 2321 mailto:[EMAIL PROTECTED] http://www.jyu.fi/~aphalo/ ,,,^..^,,, == __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
Krishna a écrit : unable to access the variables in a, by giving the command a$X. try a$V1 or a[1] or a[,1] or a$V2 etc hih __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
Potential helpers need more information. Type: head(a) and str(a) and post the results. Compare with the output of the same commands on a dataframe that does have this problem. -Don At 5:01 PM +0530 8/25/05, Krishna wrote: Hi Mr. Pedro I tried names(a) and it displayed the names as X, Y and Z. rgds snvk On 8/25/05, Pedro J. Aphalo [EMAIL PROTECTED] wrote: Hi, Did you try names(a) so see what are the names of the columns in the dataframe? Hope this helps a little. Pedro. Krishna wrote: Hi All recently i faced an unknown problem while reading the data. Can someone help me in understanding why this happened. I have .txt file containing X, Y, Z variables. I used the command a - read.table(filename, header=TRUE) after reading the file i am able to view it by tryping a. but i am unable to access the variables in a, by giving the command a$X. a$X NULL this is the output it was showing. However the same i am able to access by giving a[[1]]. i tried changing the mode by issuing command a - as.data.frame(a). But situation remains the same. look forward for experts suggestion on this. rgds snvk __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- == Pedro J. Aphalo Department of Biological and Environmental Science University of Jyväskylä P.O. Box 35, 40351 JYVÄSKYLÄ, Finland Phone +358 14 260 2339 Mobile +358 50 3721504 Fax+358 14 260 2321 mailto:[EMAIL PROTECTED] http://www.jyu.fi/~aphalo/ ,,,^..^,,, == __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
Could it be that there are spaces in the names that were read in? a - data.frame( X=1:2, Y=3:4, Z=5:6, check.names=FALSE) a X Y Z 1 1 3 5 2 2 4 6 names(a) [1] X Y Z a$X NULL Andy From: Krishna Hi Mr. Pedro I tried names(a) and it displayed the names as X, Y and Z. rgds snvk On 8/25/05, Pedro J. Aphalo [EMAIL PROTECTED] wrote: Hi, Did you try names(a) so see what are the names of the columns in the dataframe? Hope this helps a little. Pedro. Krishna wrote: Hi All recently i faced an unknown problem while reading the data. Can someone help me in understanding why this happened. I have .txt file containing X, Y, Z variables. I used the command a - read.table(filename, header=TRUE) after reading the file i am able to view it by tryping a. but i am unable to access the variables in a, by giving the command a$X. a$X NULL this is the output it was showing. However the same i am able to access by giving a[[1]]. i tried changing the mode by issuing command a - as.data.frame(a). But situation remains the same. look forward for experts suggestion on this. rgds snvk __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- == Pedro J. Aphalo Department of Biological and Environmental Science University of Jyväskylä P.O. Box 35, 40351 JYVÄSKYLÄ, Finland Phone +358 14 260 2339 Mobile +358 50 3721504 Fax+358 14 260 2321 mailto:[EMAIL PROTECTED] http://www.jyu.fi/~aphalo/ ,,,^..^,,, == __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] Problem with read.table()
Dear all, I have encountered a strange problem with read.table(). When I try to read a tab delimited file I get an error message for line 260 not being equal to 14 (see below). Using count.fields() suggests that a number of lines have length not equal to 14, but not 260. Looking at the actual file, however, I cannot see anything wrong with any lines. They all seem to have length 14, there are no double tabs etc., and the file reads correctly in other programs. Does anyone have any suggestions as to what this might stem from? I have placed a copy of the file at http://dss.ucsd.edu/~kgledits/archigos_v.1.9.asc regards, Kristian Skrede Gleditsch archigos1.9 - read.table(c:/work/work12/archigos/archigos_v.1.9.asc, + sep=\t,header=T,as.is=T,row.names=NULL) Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 260 did not have 14 elements a - count.fields(c:/work/work12/archigos/archigos_v.1.9.asc,sep=\t) a - data.frame(c(1:length(a)),a) a[a[,2]!=14,] c.1.length.a.. a 150 150 10 313 313 10 424 424 10 1189 1189 5 1510 1510 10 1514 1514 10 1590 1590 5 1600 1600 10 1612 1612 10 1618 1618 10 1619 1619 10 1709 1709 10 1722 1722 10 1981 1981 10 1985 1985 10 2112 2112 10 2178 2178 10 2208 2208 10 2224 2224 10 2530 2530 5 2536 2536 5 2573 2573 5 2928 2928 5 -- Kristian Skrede Gleditsch Department of Political Science, UCSD (On leave, University of Essex, 2005-6) Tel: +44 1206 872499, Fax: +44 1206 873234 Email: [EMAIL PROTECTED] or [EMAIL PROTECTED] http://weber.ucsd.edu/~kgledits/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem with read.table()
On Thu, 21 Jul 2005, Kristian Skrede Gleditsch wrote: Dear all, I have encountered a strange problem with read.table(). Most `strange problems' are user error, so please try not to blame your tools. When I try to read a tab delimited file I get an error message for line 260 not being equal to 14 (see below). Yes, but not line 260 in that file, but line 260 as read by scan(). Think about quotes ... it works for me with quote=, and the quote on ca line 150 is causing you to get some very large fields with embedded new lines and tabs. BTW, there is a 'R Data Import/Export' manual which goes through step-by-step the assumptions you make when using read.table with various options. Do read it now. Using count.fields() suggests that a number of lines have length not equal to 14, but not 260. Looking at the actual file, however, I cannot see anything wrong with any lines. They all seem to have length 14, there are no double tabs etc., and the file reads correctly in other programs. Does anyone have any suggestions as to what this might stem from? I have placed a copy of the file at http://dss.ucsd.edu/~kgledits/archigos_v.1.9.asc regards, Kristian Skrede Gleditsch archigos1.9 - read.table(c:/work/work12/archigos/archigos_v.1.9.asc, + sep=\t,header=T,as.is=T,row.names=NULL) Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 260 did not have 14 elements a - count.fields(c:/work/work12/archigos/archigos_v.1.9.asc,sep=\t) a - data.frame(c(1:length(a)),a) a[a[,2]!=14,] c.1.length.a.. a 150 150 10 313 313 10 424 424 10 1189 1189 5 1510 1510 10 1514 1514 10 1590 1590 5 1600 1600 10 1612 1612 10 1618 1618 10 1619 1619 10 1709 1709 10 1722 1722 10 1981 1981 10 1985 1985 10 2112 2112 10 2178 2178 10 2208 2208 10 2224 2224 10 2530 2530 5 2536 2536 5 2573 2573 5 2928 2928 5 -- Kristian Skrede Gleditsch Department of Political Science, UCSD (On leave, University of Essex, 2005-6) Tel: +44 1206 872499, Fax: +44 1206 873234 Email: [EMAIL PROTECTED] or [EMAIL PROTECTED] http://weber.ucsd.edu/~kgledits/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem with read.table()
I don't really understand it, but the problem seems to come down to the presence of apostrophes (single right quotes ') in the text strings. The first of these occurs in line 149 (not counting the header line). If one tries to scan just that line, one gets a vector of length 10. Fields 10 to 14 are read as a single field. Upon deleting the apostrophe, I got a a vector of length 14 (OMMM!) The help on scan() talks about a quote argument and indicates that if sep is not the newline character, then quote defaults to '\. It remarks that you can include quotes inside strings by doubling them. I did a global substitution, changing ' to '' throughout, and the read.table() worked (i.e. didn't complain and yielded up a data frame of dimension 2935 x 14). But no apostrophes appeared in the fields in the resulting data frame. The help seems to indicate that you can get around the problem by specifying quote = some character which doesn't appear in the file. (This also saves having to do a global edit.) I tried quote=# and it seemed to work in this instance. And the apostrophes ***did*** appear in the strings in the data frame. I don't grok why the complaint shows up at line 260 rather than immediately at line 149 but it's a start. cheers, Rolf Turner [EMAIL PROTECTED] Original message: From [EMAIL PROTECTED] Thu Jul 21 10:12:09 2005 Date: Thu, 21 Jul 2005 14:11:36 +0100 From: Kristian Skrede Gleditsch [EMAIL PROTECTED] User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: r-help@stat.math.ethz.ch X-Essex-ClamAV: No malware found X-Essex-MailScanner: Found to be clean X-Essex-MailScanner-SpamCheck: not spam, SpamAssassin (score=-2.82, required 5, autolearn=disabled, ALL_TRUSTED -2.82) X-MailScanner-From: [EMAIL PROTECTED] X-Virus-Scanned: by amavisd-new at stat.math.ethz.ch Subject: [R] Problem with read.table() X-BeenThere: r-help@stat.math.ethz.ch X-Mailman-Version: 2.1.6 List-Id: Main R Mailing List: Primary help r-help.stat.math.ethz.ch List-Unsubscribe: https://stat.ethz.ch/mailman/listinfo/r-help, mailto:[EMAIL PROTECTED] List-Archive: https://stat.ethz.ch/pipermail/r-help List-Post: mailto:r-help@stat.math.ethz.ch List-Help: mailto:[EMAIL PROTECTED] List-Subscribe: https://stat.ethz.ch/mailman/listinfo/r-help, mailto:[EMAIL PROTECTED] Content-Transfer-Encoding: 7bit X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on erdos.math.unb.ca X-Spam-Math-Flag: NO X-Spam-Math-Status: No, hits=0.0 required=5.0 tests=BAYES_50 autolearn=no version=3.0.4 Dear all, I have encountered a strange problem with read.table(). When I try to read a tab delimited file I get an error message for line 260 not being equal to 14 (see below). Using count.fields() suggests that a number of lines have length not equal to 14, but not 260. Looking at the actual file, however, I cannot see anything wrong with any lines. They all seem to have length 14, there are no double tabs etc., and the file reads correctly in other programs. Does anyone have any suggestions as to what this might stem from? I have placed a copy of the file at http://dss.ucsd.edu/~kgledits/archigos_v.1.9.asc regards, Kristian Skrede Gleditsch archigos1.9 - read.table(c:/work/work12/archigos/archigos_v.1.9.asc, + sep=\t,header=T,as.is=T,row.names=NULL) Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 260 did not have 14 elements a - count.fields(c:/work/work12/archigos/archigos_v.1.9.asc,sep=\t) a - data.frame(c(1:length(a)),a) a[a[,2]!=14,] c.1.length.a.. a 150 150 10 313 313 10 424 424 10 1189 1189 5 1510 1510 10 1514 1514 10 1590 1590 5 1600 1600 10 1612 1612 10 1618 1618 10 1619 1619 10 1709 1709 10 1722 1722 10 1981 1981 10 1985 1985 10 2112 2112 10 2178 2178 10 2208 2208 10 2224 2224 10 2530 2530 5 2536 2536 5 2573 2573 5 2928 2928 5 -- Kristian Skrede Gleditsch Department of Political Science, UCSD (On leave, University of Essex, 2005-6) Tel: +44 1206 872499, Fax: +44 1206 873234 Email: [EMAIL PROTECTED] or [EMAIL PROTECTED] http://weber.ucsd.edu/~kgledits/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem with read.table()
Thanks to all who responded to my earlier message. The problem lies in that apostrophes (i.e., ') in some of the text fields are read as quotes. The file can be read without problems setting quotes= in read.table. Incidently, read.delim() also works, even without setting quotes= explicitly. best regards, Kristian Skrede Gleditsch Department of Political Science, UCSD (On leave, University of Essex, 2005-6) Tel: +44 1206 872499, Fax: +44 1206 873234 Email: [EMAIL PROTECTED] or [EMAIL PROTECTED] http://weber.ucsd.edu/~kgledits/ Kristian Skrede Gleditsch wrote: Dear all, I have encountered a strange problem with read.table(). When I try to read a tab delimited file I get an error message for line 260 not being equal to 14 (see below). Using count.fields() suggests that a number of lines have length not equal to 14, but not 260. Looking at the actual file, however, I cannot see anything wrong with any lines. They all seem to have length 14, there are no double tabs etc., and the file reads correctly in other programs. Does anyone have any suggestions as to what this might stem from? I have placed a copy of the file at http://dss.ucsd.edu/~kgledits/archigos_v.1.9.asc regards, Kristian Skrede Gleditsch archigos1.9 - read.table(c:/work/work12/archigos/archigos_v.1.9.asc, + sep=\t,header=T,as.is=T,row.names=NULL) Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 260 did not have 14 elements a - count.fields(c:/work/work12/archigos/archigos_v.1.9.asc,sep=\t) a - data.frame(c(1:length(a)),a) a[a[,2]!=14,] c.1.length.a.. a 150 150 10 313 313 10 424 424 10 1189 1189 5 1510 1510 10 1514 1514 10 1590 1590 5 1600 1600 10 1612 1612 10 1618 1618 10 1619 1619 10 1709 1709 10 1722 1722 10 1981 1981 10 1985 1985 10 2112 2112 10 2178 2178 10 2208 2208 10 2224 2224 10 2530 2530 5 2536 2536 5 2573 2573 5 2928 2928 5 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] problem with read.table
Hello R-users, I apologize for my question but I'm a newbie. I want to read a file which columns separator is \t. At the end of each row there is a \n to go to the following line. The three first lines are remarks lines and the fourth contains columns titles ( variables names, ids, dates, calculated values, observed values...) . I do: read.table(myFile, header=TRUE, sep = \t, skip = 3) I obtain a strange result, lines are in a bad order: cell6/voxel15 1998/365a 2.0 1.0 0.55 0.2748257492065 0\nRendement de la culture 0.0 crop4 0/0a0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/75a0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/150a 0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/225a 0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/300a 0.0 1.0 0.0 3.0368848 0\nRayonnement diffu reçu 0.0 crop1 0/0a0.0 2.0 0.0 0.0 0\nRayonnement diffu reçu 0.0 crop1 1998/50a0.0 2.0 0.0 6.8406434 0\nRayonnement diffu reçu 0.0 crop1 1998/100a 0.0 2.0 0.0 14.235084 0\nRayonnement diffu reçu 0.0 crop1 1998/150a 0.0 2.0 0.0 14.15452 0\nRayonnement diffu reçu 0.0 crop1 1998/200a 0.0 2.0 0.0 13.691006 0\nRayonnement diffu reçu 0.0 crop1 1998/250a 0.0 2.0 0.0 10.997387 0\nRayonnement diffu reçu 0.0 crop1 1998/300a 0.0 2.0 0.0 10.94 0\nRayonnement diffu reçu 0.0 crop1 1998/350a 0.0 2.0 0.0 4.198115 0\nRayonnement diffu reçu 0.0 crop9 0/0a2.0 0.0 0.0 0.0 0\nRayonnement diffu reçu 0.0 crop9 1998/50a2.0 0.0 0.0 6.8406434 0\nRayonnement diffu reçu 0.0 crop9 1998/100a 2.0 0.0 0.0 14.235084 0\nRayonnement diffu reçu 0.0 crop9 1998/150a 2.0 0.0 0.0 14.15452 0\nRayonnement diffu reçu 0.0 crop9 1998/200a 2.0 0.0 0.0 13.676454 0\nRayonnement diffu reçu 0.0 crop9 1998/250a 2.0 0.0 0.0 10.983188 0\nRayonnement diffu reçu 0.0 crop9 1998/300a 2.0 0.0 0.0 10.94 0\nRayonnement diffu reçu 0.0 crop9 1998/350a 2.0 0.0 0.0 4.198115 0\n weightingid date x yz calculated observed 1 0 tree1 1998/365a 1.5 1.5 0.00 1.58e+02 162.000 2 0 tree1 0/0a 1.5 1.5 0.00 6.242254e-030.007 3 0 tree1 1998/365a 1.5 1.5 0.00 1.038187e-020.011 4 0 tree1 1998/365a 1.5 1.5 0.00 1.008111e+000.000 5 0 cell4/voxel23 1998/365a 0.0 1.0 0.55 0.00e+000.000 6 0 cell5/voxel18 1998/365a 1.0 1.0 0.25 0.00e+000.000 7 0 cell5/voxel20 1998/365a 1.0 1.0 0.90 0.00e+000.000 8 0 cell6/voxel15 1998/365a 2.0 1.0 0.55 0.00e+000.000 9NA NA NA NA NA NA The \n is read like a word and not like a symbol to skip a line. What should I do? Thanks __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
This is a strange result. I couldn't have a similar result, even with your exact call to read.table. Maybe there is a problem with the file (possibly some white space characters not cleaned). If you send the first 5 lines of your text file I could say something more. On Mon, 2004-07-19 at 09:05, Vincent MUTEAUD wrote: Hello R-users, I apologize for my question but I'm a newbie. I want to read a file which columns separator is \t. At the end of each row there is a \n to go to the following line. The three first lines are remarks lines and the fourth contains columns titles ( variables names, ids, dates, calculated values, observed values...) . I do: read.table(myFile, header=TRUE, sep = \t, skip = 3) I obtain a strange result, lines are in a bad order: cell6/voxel15 1998/365a 2.0 1.0 0.55 0.2748257492065 0\nRendement de la culture 0.0 crop4 0/0a0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/75a0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/150a 0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/225a 0.0 1.0 0.0 0.0 0\nRendement de la culture 0.0 crop4 1998/300a 0.0 1.0 0.0 3.0368848 0\nRayonnement diffu reçu 0.0 crop1 0/0a0.0 2.0 0.0 0.0 0\nRayonnement diffu reçu 0.0 crop1 1998/50a0.0 2.0 0.0 6.8406434 0\nRayonnement diffu reçu 0.0 crop1 1998/100a 0.0 2.0 0.0 14.235084 0\nRayonnement diffu reçu 0.0 crop1 1998/150a 0.0 2.0 0.0 14.15452 0\nRayonnement diffu reçu 0.0 crop1 1998/200a 0.0 2.0 0.0 13.691006 0\nRayonnement diffu reçu 0.0 crop1 1998/250a 0.0 2.0 0.0 10.997387 0\nRayonnement diffu reçu 0.0 crop1 1998/300a 0.0 2.0 0.0 10.94 0\nRayonnement diffu reçu 0.0 crop1 1998/350a 0.0 2.0 0.0 4.198115 0\nRayonnement diffu reçu 0.0 crop9 0/0a2.0 0.0 0.0 0.0 0\nRayonnement diffu reçu 0.0 crop9 1998/50a2.0 0.0 0.0 6.8406434 0\nRayonnement diffu reçu 0.0 crop9 1998/100a 2.0 0.0 0.0 14.235084 0\nRayonnement diffu reçu 0.0 crop9 1998/150a 2.0 0.0 0.0 14.15452 0\nRayonnement diffu reçu 0.0 crop9 1998/200a 2.0 0.0 0.0 13.676454 0\nRayonnement diffu reçu 0.0 crop9 1998/250a 2.0 0.0 0.0 10.983188 0\nRayonnement diffu reçu 0.0 crop9 1998/300a 2.0 0.0 0.0 10.94 0\nRayonnement diffu reçu 0.0 crop9 1998/350a 2.0 0.0 0.0 4.198115 0\n weightingid date x yz calculated observed 1 0 tree1 1998/365a 1.5 1.5 0.00 1.58e+02 162.000 2 0 tree1 0/0a 1.5 1.5 0.00 6.242254e-030.007 3 0 tree1 1998/365a 1.5 1.5 0.00 1.038187e-020.011 4 0 tree1 1998/365a 1.5 1.5 0.00 1.008111e+000.000 5 0 cell4/voxel23 1998/365a 0.0 1.0 0.55 0.00e+000.000 6 0 cell5/voxel18 1998/365a 1.0 1.0 0.25 0.00e+000.000 7 0 cell5/voxel20 1998/365a 1.0 1.0 0.90 0.00e+000.000 8 0 cell6/voxel15 1998/365a 2.0 1.0 0.55 0.00e+000.000 9NA NA NA NA NA NA The \n is read like a word and not like a symbol to skip a line. What should I do? Thanks __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
The email has changed the file. Please send attached. On Mon, 2004-07-19 at 09:43, Vincent MUTEAUD wrote: Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
If your file looks like attached, you should call read.table(temp.txt, header=TRUE, sep=\t, skip=3, quote=) On Mon, 2004-07-19 at 09:43, Vincent MUTEAUD wrote: Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
Sorry, I may have suspect that the format will be changed. A 10:00 19/07/2004 +0100, Pedro Rodrigues a écrit : The email has changed the file. Please send attached. On Mon, 2004-07-19 at 09:43, Vincent MUTEAUD wrote: Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 Hauteur totale de l'arbre 0.0 tree1 1998/365a 1.5 1.5 0.0 1.008192703247 0 Densité de racines fines de l'arbre 0.0 cell4/voxel22 1998/365a 0.0 1.0 0.250.0 0 Densité de racines fines de l'arbre 0.0 cell4/voxel23 1998/365a 0.0 1.0 0.550.0 0 Densité de racines fines de l'arbre 0.0 cell4/voxel24 1998/365a 0.0 1.0 0.9 0.0 0 Densité de racines fines de l'arbre 0.0 cell5/voxel18 1998/365a 1.0 1.0 0.250.0 0 Densité de racines fines de l'arbre 0.0 cell5/voxel19 1998/365a 1.0 1.0 0.550.0 0 Densité de racines fines de l'arbre 0.0 cell5/voxel20 1998/365a 1.0 1.0 0.9 0.0 0 Densité de racines fines de l'arbre 0.0 cell6/voxel14 1998/365a 2.0 1.0 0.250.0 0 Densité de racines fines de l'arbre 0.0 cell6/voxel15 1998/365a 2.0 1.0 0.550.0 0 Densité de racines fines de l'arbre 0.0 cell6/voxel16 1998/365a 2.0 1.0 0.9 0.0 0 Teneur en eau 0.0 cell6/voxel15 1998/365a 2.0 1.0 0.55 0.2748257492065 0 Rendement de la culture 0.0 crop4 0/0a0.0 1.0 0.0 0.0 0 Rendement de la culture 0.0 crop4 1998/75a0.0 1.0 0.0 0.0 0 Rendement de la culture 0.0 crop4 1998/150a 0.0 1.0 0.0 0.0 0 Rendement de la culture 0.0 crop4 1998/225a 0.0 1.0 0.0 0.0 0 Rendement de la culture 0.0 crop4 1998/300a 0.0 1.0 0.0 3.0368848 0 Rayonnement diffu reçu 0.0 crop1 0/0a0.0 2.0 0.0 0.0 0 Rayonnement diffu reçu 0.0 crop1 1998/50a0.0 2.0 0.0 6.8406434 0 Rayonnement diffu reçu 0.0 crop1 1998/100a 0.0 2.0 0.0 14.235084 0 Rayonnement diffu reçu 0.0 crop1 1998/150a 0.0 2.0 0.0 14.154520 Rayonnement diffu reçu 0.0 crop1 1998/200a 0.0 2.0 0.0 13.691006 0 Rayonnement diffu reçu 0.0 crop1 1998/250a 0.0 2.0 0.0 10.997387 0 Rayonnement diffu reçu 0.0 crop1 1998/300a 0.0 2.0 0.0 10.94 0 Rayonnement diffu reçu 0.0 crop1 1998/350a 0.0 2.0 0.0 4.1981150 Rayonnement diffu reçu 0.0 crop9 0/0a2.0 0.0 0.0 0.0 0 Rayonnement diffu reçu 0.0 crop9 1998/50a2.0 0.0 0.0 6.8406434 0 Rayonnement diffu reçu 0.0 crop9 1998/100a 2.0 0.0 0.0 14.235084 0 Rayonnement diffu reçu 0.0
Re: [R] problem with read.table
That's allright, thanks a lot. What is the signification of quote exactly? A 10:08 19/07/2004 +0100, Pedro Rodrigues a écrit : If your file looks like attached, you should call read.table(temp.txt, header=TRUE, sep=\t, skip=3, quote=) On Mon, 2004-07-19 at 09:43, Vincent MUTEAUD wrote: Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
The option quote states the character that encloses strings in your file. for instance if you had a file with Name Height Tree1 100.3 you should call read.table with quote=\. On Mon, 2004-07-19 at 10:25, Vincent MUTEAUD wrote: That's allright, thanks a lot. What is the signification of quote exactly? A 10:08 19/07/2004 +0100, Pedro Rodrigues a écrit : If your file looks like attached, you should call read.table(temp.txt, header=TRUE, sep=\t, skip=3, quote=) On Mon, 2004-07-19 at 09:43, Vincent MUTEAUD wrote: Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
Thank you for your help and the quickness of your answers. A 10:27 19/07/2004 +0100, Pedro Rodrigues a écrit : The option quote states the character that encloses strings in your file. for instance if you had a file with Name Height Tree1 100.3 you should call read.table with quote=\. On Mon, 2004-07-19 at 10:25, Vincent MUTEAUD wrote: That's allright, thanks a lot. What is the signification of quote exactly? A 10:08 19/07/2004 +0100, Pedro Rodrigues a écrit : If your file looks like attached, you should call read.table(temp.txt, header=TRUE, sep=\t, skip=3, quote=) On Mon, 2004-07-19 at 09:43, Vincent MUTEAUD wrote: Thanks for your quick answer but I don't see the escape character \n in myFile I see it on the result of my R command. This is an extract of myFile: # Capsis 4.1.3 generated file - Mon Jul 19 10:39:56 CEST 2004 varName weighting id datex y z calculated observed Date de débourrement0.0 tree1 1998/365a 1.5 1.5 0.0 158 162 Diamètre du tronc 0.0 tree1 0/0a1.5 1.5 0.0 0.0062422542832791805 0.007 Diamètre du tronc 0.0 tree1 1998/365a 1.5 1.5 0.0 0.0103818718343973160.011 Hauteur totale de l'arbre 0.0 tree1 0/0a1.5 1.5 0.0 1.0 0 I don't know why \n appears in R. A 10:40 19/07/2004 +0200, [EMAIL PROTECTED] a écrit : You should'nt see the escape character \n on myfile. Try deleting with a text editor \n A.S. Alessandro Semeria Models and Simulations Laboratory Montecatini Environmental Research Center (Edison Group), Via Ciro Menotti 48, 48023 Marina di Ravenna (RA), Italy Tel. +39 544 536811 Fax. +39 544 538663 E-mail: [EMAIL PROTECTED] [[alternative HTML version deleted]] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] problem with read.table
Any ideas why read.table complains about not correct number of elements in line while readLine/strsplit indicate that all lines have the same number of elements ? R tbl - read.table('tmp', header = T, sep = '\t') Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 32 did not have 27 elements lines - readLines('tmp') v - 1:length(lines) i - 0; for (line in lines) { i - i + 1; v[i] - length(strsplit(line, '\t')[[1]]) } v [1] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 [26] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 [51] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 sum((v - v[1])^2) [1] 0 length(strsplit(lines[32], '\t')[[1]]) [1] 27 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
[EMAIL PROTECTED] writes: Any ideas why read.table complains about not correct number of elements in line while readLine/strsplit indicate that all lines have the same number of elements ? R tbl - read.table('tmp', header = T, sep = '\t') Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 32 did not have 27 elements lines - readLines('tmp') v - 1:length(lines) i - 0; for (line in lines) { i - i + 1; v[i] - length(strsplit(line, '\t')[[1]]) } v [1] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 [26] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 [51] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 sum((v - v[1])^2) [1] 0 length(strsplit(lines[32], '\t')[[1]]) [1] 27 Try count.fields to see what line is giving problems. Watch especially for comment characters (default is '#') and quote characters. My good friends in Biological Sciences (including my spouse and one of my children) have a habit of incorporating 3' and 5' in descriptive text and that always trips me up. __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] problem with read.table
On Tue, 3 Feb 2004 [EMAIL PROTECTED] wrote: Any ideas why read.table complains about not correct number of elements in line while readLine/strsplit indicate that all lines have the same number of elements ? That is what count.fields is for. Setting fill=TRUE in read.table can help detection, too. One guess is that you have a comment character on that line, but one thing you did not show us is the appropriate lines of the file. tbl - read.table('tmp', header = T, sep = '\t') Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : line 32 did not have 27 elements lines - readLines('tmp') v - 1:length(lines) i - 0; for (line in lines) { i - i + 1; v[i] - length(strsplit(line, '\t')[[1]]) } v [1] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 [26] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 [51] 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 27 sum((v - v[1])^2) [1] 0 length(strsplit(lines[32], '\t')[[1]]) [1] 27 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] Problem with read.table
Should that be sep=\t ? On Fri, 21 Mar 2003, sabrina servanty wrote: Dear all, I was used to work on R1.6 and I have now passed on R1.6.2 but I can't read my file (and that is a big problem!!). I made a data sheet with some spreadsheet in Excell, and save it as separeted by tab .txt. I write in R read.table (file.txt,h=T,sep=/t,dec=,) But R consider that I have only one column (eG one variable)!!! I have tried a lot of thing (I don't wrote the spreadsheet,I have verified in word that my column was really separated by tabulation...) but I really don't find. It may be really simple but I'm not really good to speak with R! Regards Sabrina Servanty. __ Boîte aux lettres - Caramail - http://www.caramail.com -- 318 Carr Hall[EMAIL PROTECTED] Zoology Department, University of Floridahttp://www.zoo.ufl.edu/bolker Box 118525 (ph) 352-392-5697 Gainesville, FL 32611-8525 (fax) 352-392-3704 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
RE: [R] Problem with read.table
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of sabrina servanty Sent: Friday, March 21, 2003 1:22 PM To: [EMAIL PROTECTED] Subject: [R] Problem with read.table Dear all, I was used to work on R1.6 and I have now passed on R1.6.2 but I can't read my file (and that is a big problem!!). I made a data sheet with some spreadsheet in Excell, and save it as separeted by tab .txt. I write in R read.table (file.txt,h=T,sep=/t,dec=,) But R consider that I have only one column (eG one variable)!!! I have tried a lot of thing (I don't wrote the spreadsheet,I have verified in word that my column was really separated by tabulation) but I really don't find. It may be really simple but I'm not really good to speak with R! Regards Sabrina Servanty. - Sabrina, Try reversing the / in your 'sep = /t' argument. You have it reveresed at the moment, assuming that is is copied here as you are using it. The tab character is: \t So the command should be: read.table (file.txt,h=T,sep=\t,dec=,) HTH, Marc Schwartz __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] Problem with read.table
How about replacing /t by \t ? Jerome __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help