|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Query: how to add quotes when importing a txt fileDear R users, I have a txt file of the form 10092007 24.62 24.31 24.90 11092007 19.20 23.17 22.10 13092007 24.71 27.33 23.10 14092007 27.33 27.90 24.10 15092007 28.22 28.55 24.30 16092007 28.53 29.24 27.40 17092007 24.19 30.64 26.80 18092007 22.60 20.62 28.40 19092007 8.89 1.70 14.70 20092007 21.27 2.92 17.30 21092007 22.38 24.72 8.80 22092007 23.94 24.73 20.40 23092007 25.33 25.12 22.60 24092007 24.91 22.46 21.40 25092007 23.52 25.00 21.70 26092007 2.50 2.29 8.80 and I have to import it into R. The problem is that I have to add the quotes at the beginning and end of the file, like shown here below. I tried to use read.zoo (in fact I will have to use the zoo package afterwards), but I have not been able to do what I need. Could you please help me in that? (not necessarily with read.zoo, any method will be fine!) "10092007 24.62 24.31 24.90 11092007 19.20 23.17 22.10 13092007 24.71 27.33 23.10 14092007 27.33 27.90 24.10 15092007 28.22 28.55 24.30 16092007 28.53 29.24 27.40 17092007 24.19 30.64 26.80 18092007 22.60 20.62 28.40 19092007 8.89 1.70 14.70 20092007 21.27 2.92 17.30 21092007 22.38 24.72 8.80 22092007 23.94 24.73 20.40 23092007 25.33 25.12 22.60 24092007 24.91 22.46 21.40 25092007 23.52 25.00 21.70 26092007 2.50 2.29 8.80" thank you Stefano [[alternative HTML version deleted]] ______________________________________________ R-help@... 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: Query: how to add quotes when importing a txt fileOn Fri, May 9, 2008 at 8:52 AM, Stefano Sofia
<stefano.sofia@...> wrote: > > Dear R users, > I have a txt file of the form > > 10092007 24.62 24.31 24.90 > 11092007 19.20 23.17 22.10 > 13092007 24.71 27.33 23.10 > 14092007 27.33 27.90 24.10 > 15092007 28.22 28.55 24.30 > 16092007 28.53 29.24 27.40 > 17092007 24.19 30.64 26.80 > 18092007 22.60 20.62 28.40 > 19092007 8.89 1.70 14.70 > 20092007 21.27 2.92 17.30 > 21092007 22.38 24.72 8.80 > 22092007 23.94 24.73 20.40 > 23092007 25.33 25.12 22.60 > 24092007 24.91 22.46 21.40 > 25092007 23.52 25.00 21.70 > 26092007 2.50 2.29 8.80 > > and I have to import it into R. The problem is that I have to add the quotes at the beginning and end of the file That is not correct. The file is fine the way it is. Read it in using read.zoo. See ?read.zoo and read the three vignettes that come with zoo. ______________________________________________ R-help@... 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: Query: how to add quotes when importing a txt fileHi Stefano,
Take a look at ?read.table and its friends. Now, assuming that your file is "data.txt" you can use, for example: # Option 1 > df=read.table('your.ubication.here/data.txt',header=FALSE) > df # Option 2 Copy your data set in the clipboard and write this in the R Console: > df=read.table('clipboard') > df In my opinion, I think you don't need the quotes at least you use > y="10092007 24.62 24.31 24.90 11092007 19.20 23.17 22.10 13092007 24.71 27.33 23.10 14092007 27.33 27.90 24.10 15092007 28.22 28.55 24.30 16092007 28.53 29.24 27.40 17092007 24.19 30.64 26.80 18092007 22.60 20.62 28.40 19092007 8.89 1.70 14.70 20092007 21.27 2.92 17.30 21092007 22.38 24.72 8.80 22092007 23.94 24.73 20.40 23092007 25.33 25.12 22.60 24092007 24.91 22.46 21.40 25092007 23.52 25.00 21.70 26092007 2.50 2.29 8.80" > df=read.table(textConnection(y),header=FALSE) > df HTH, Jorge On Fri, May 9, 2008 at 8:52 AM, Stefano Sofia < stefano.sofia@...> wrote: > > Dear R users, > I have a txt file of the form > > 10092007 24.62 24.31 24.90 > 11092007 19.20 23.17 22.10 > 13092007 24.71 27.33 23.10 > 14092007 27.33 27.90 24.10 > 15092007 28.22 28.55 24.30 > 16092007 28.53 29.24 27.40 > 17092007 24.19 30.64 26.80 > 18092007 22.60 20.62 28.40 > 19092007 8.89 1.70 14.70 > 20092007 21.27 2.92 17.30 > 21092007 22.38 24.72 8.80 > 22092007 23.94 24.73 20.40 > 23092007 25.33 25.12 22.60 > 24092007 24.91 22.46 21.40 > 25092007 23.52 25.00 21.70 > 26092007 2.50 2.29 8.80 > > and I have to import it into R. The problem is that I have to add the > quotes at the beginning and end of the file, like shown here below. I tried > to use read.zoo (in fact I will have to use the zoo package afterwards), but > I have not been able to do what I need. > Could you please help me in that? (not necessarily with read.zoo, any > method will be fine!) > > "10092007 24.62 24.31 24.90 > 11092007 19.20 23.17 22.10 > 13092007 24.71 27.33 23.10 > 14092007 27.33 27.90 24.10 > 15092007 28.22 28.55 24.30 > 16092007 28.53 29.24 27.40 > 17092007 24.19 30.64 26.80 > 18092007 22.60 20.62 28.40 > 19092007 8.89 1.70 14.70 > 20092007 21.27 2.92 17.30 > 21092007 22.38 24.72 8.80 > 22092007 23.94 24.73 20.40 > 23092007 25.33 25.12 22.60 > 24092007 24.91 22.46 21.40 > 25092007 23.52 25.00 21.70 > 26092007 2.50 2.29 8.80" > > thank you > Stefano > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@... 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 [[alternative HTML version deleted]] ______________________________________________ R-help@... 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: Query: how to add quotes when importing a txt fileHi Stefano,
Why do you *need* to add the quotes to the text file? If you leave them out, any of the standard methods of reading data (i.e., read.table(filename, sep="") should work. See help(read.table), help(scan), or help(read.fwf) for more info. Mike Stefano Sofia wrote: > Dear R users, > I have a txt file of the form > > 10092007 24.62 24.31 24.90 > 11092007 19.20 23.17 22.10 > 13092007 24.71 27.33 23.10 > 14092007 27.33 27.90 24.10 > 15092007 28.22 28.55 24.30 > 16092007 28.53 29.24 27.40 > 17092007 24.19 30.64 26.80 > 18092007 22.60 20.62 28.40 > 19092007 8.89 1.70 14.70 > 20092007 21.27 2.92 17.30 > 21092007 22.38 24.72 8.80 > 22092007 23.94 24.73 20.40 > 23092007 25.33 25.12 22.60 > 24092007 24.91 22.46 21.40 > 25092007 23.52 25.00 21.70 > 26092007 2.50 2.29 8.80 > > and I have to import it into R. The problem is that I have to add the quotes at the beginning and end of the file, like shown here below. I tried to use read.zoo (in fact I will have to use the zoo package afterwards), but I have not been able to do what I need. > Could you please help me in that? (not necessarily with read.zoo, any method will be fine!) > > "10092007 24.62 24.31 24.90 > 11092007 19.20 23.17 22.10 > 13092007 24.71 27.33 23.10 > 14092007 27.33 27.90 24.10 > 15092007 28.22 28.55 24.30 > 16092007 28.53 29.24 27.40 > 17092007 24.19 30.64 26.80 > 18092007 22.60 20.62 28.40 > 19092007 8.89 1.70 14.70 > 20092007 21.27 2.92 17.30 > 21092007 22.38 24.72 8.80 > 22092007 23.94 24.73 20.40 > 23092007 25.33 25.12 22.60 > 24092007 24.91 22.46 21.40 > 25092007 23.52 25.00 21.70 > 26092007 2.50 2.29 8.80" > > thank you > Stefano > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@... 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. > -- Michael D. Rennie Ph.D. Candidate University of Toronto at Mississauga 3359 Missisagua Rd. N. Mississauga, ON L5L 1C6 Ph: 905-828-5452 Fax: 905-828-3792 www.utm.utoronto.ca/~w3rennie ______________________________________________ R-help@... 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: Query: how to add quotes when importing a txt fileJust to follow up based on offline discussion the problem is that
column one values were being interpreted as numeric (since they are all numbers) so that, for example, 09122007 was interpreted as 9122007 without the leading zero. In such a case the day was regarded as 91 which, of course, can't be. The first column can be forced to be character like this: read.zoo("myfile.txt", format = "%d%m%Y", colClasses = c(V1 = "character")) Its possible that some additional smarts by read.zoo could handle this automatically but for now the above will do it and I've added additional warnings to ?read.zoo (in addition to a prior example already there which also made reference to the numeric/character problem but might have been less obvious). On Fri, May 9, 2008 at 9:01 AM, Gabor Grothendieck <ggrothendieck@...> wrote: > On Fri, May 9, 2008 at 8:52 AM, Stefano Sofia > <stefano.sofia@...> wrote: >> >> Dear R users, >> I have a txt file of the form >> >> 10092007 24.62 24.31 24.90 >> 11092007 19.20 23.17 22.10 >> 13092007 24.71 27.33 23.10 >> 14092007 27.33 27.90 24.10 >> 15092007 28.22 28.55 24.30 >> 16092007 28.53 29.24 27.40 >> 17092007 24.19 30.64 26.80 >> 18092007 22.60 20.62 28.40 >> 19092007 8.89 1.70 14.70 >> 20092007 21.27 2.92 17.30 >> 21092007 22.38 24.72 8.80 >> 22092007 23.94 24.73 20.40 >> 23092007 25.33 25.12 22.60 >> 24092007 24.91 22.46 21.40 >> 25092007 23.52 25.00 21.70 >> 26092007 2.50 2.29 8.80 >> >> and I have to import it into R. The problem is that I have to add the quotes at the beginning and end of the file > > That is not correct. The file is fine the way it is. Read it in > using read.zoo. See ?read.zoo and read the > three vignettes that come with zoo. > ______________________________________________ R-help@... 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. |
| Free Forum Powered by Nabble | Forum Help |