Re: [R] How to extract folowing data?

From: Ben Tupper <PemaquidRiver_at_tidewater.net>
Date: Mon, 14 Jul 2008 07:30:47 -0400

On Jul 14, 2008, at 3:03 AM, Megh Dal wrote:

> Hi,
> following data is taken from http://www.economagic.com/em-cgi/
> data.exe/var/west-texas-crude-long. Problem with this data is when
> you copy it from this site you would get something like that :
>
> 1946 063331.27
> 1946 079991.27
> 1946 087771.52
> 1946 096661.52
>
> They should be interpret in following way :
>
> 1946 063331.27 this means : on 1946, June price was 1.27. Can
> anyone please suggest me the easiest way with R to get extracted
> the entire series?
>
>

Hi,

You can extract the year, month and price with the following:

 > s = c("1946 063331.27", "1946 079991.27")
 > nc = nchar(s)
 > y = substr(s, 1,4)
 > m = substr(s, 6,7)
 > p = substr(s,nc-3,nc)
 > y

[1] "1946" "1946"
 > m
[1] "06" "07"
 > p
[1] "1.27" "1.27"

But you will want to pay attention to what happens when the price requires more digits.

Cheers,
Ben

P.S. Wow! A 20% increase in the cost of oil in one month! Will wonders never cease?

Ben Tupper
PemaquidRiver_at_tidewater.net

I GoodSearch for Ashwood Waldorf School.

Raise money for your favorite charity or school just by searching the Internet with GoodSearch - www.goodsearch.com - powered by Yahoo!



R-help_at_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. Received on Mon 14 Jul 2008 - 11:37:18 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 14 Jul 2008 - 12:31:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive