[R] Importing time series

Gabor Grothendieck ggrothendieck at gmail.com
Wed Jul 29 10:41:34 CEST 2009


There are no delimiters between your fields!   read.table and friends
require such delimiters.  As the input is ambiguous we have assumed
the field widths shown in the read.fwf statement and you can modify
it appropriately to use the correct field widths.  Also, evidently your
data has errors in it with decimals points likely missing on the 6th
and the 28th of July.

ss <- "7/2/1982312.7212.0618.397471390.4
7/6/1982311208.4518.227521392.2
7/7/1982306.7206.4118.327381385
7/8/1982313.5207.1918.567221392.6
7/13/1982352.5205.7918.857301485.7
7/14/1982352.7206.2718.757211494.9
7/15/1982350.2207.1218.717121491.6
7/20/1982347.7205.3218.626611508.8
7/21/1982366.5204.6618.776541575.6
7/26/1982352.2208.418.526541554.9
7/27/1982351.2212.1718.516591523.6
7/28/1982347213.9618.226541499.3
7/30/1982342.9215.8318.066581467.9
8/3/1982349.2216.3718.147281536.6"

DF1 <- read.table(textConnection(ss), sep = "/", as.is = TRUE)
DF2 <- read.fwf(textConnection(DF1$V3), c(4, 5, 5, 5, 5))
library(zoo)
z <- zoo(as.matrix(DF2[-1]), as.Date(paste(DF2$V1, DF1$V1, DF1$V2, sep = "-")))

This gives the following:

> z
                V2      V3      V4         V5
1982-07-02   312.7 212.000 618.300 97471390.4
1982-07-06 31120.0   8.451   8.227   521392.2
1982-07-07   306.7 206.400 118.300 27381385.0
1982-07-08   313.5 207.100 918.500 67221392.6
1982-07-13   352.5 205.700 918.800 57301485.7
1982-07-14   352.7 206.200 718.700 57211494.9
1982-07-15   350.2 207.100 218.700 17121491.6
1982-07-20   347.7 205.300 218.600 26611508.8
1982-07-21   366.5 204.600 618.700 76541575.6
1982-07-26   352.2 208.400  18.520  6541554.9
1982-07-27   351.2 212.100 718.500 16591523.6
1982-07-28 34721.0   3.961   8.226   541499.3
1982-07-30   342.9 215.800 318.000 66581467.9
1982-08-03   349.2 216.300 718.100 47281536.6


On Wed, Jul 29, 2009 at 4:22 AM, Bogaso<bogaso.christofer at gmail.com> wrote:
>
> Thanks for reply. However still problem is there. Here I am giving some parts
> of the data :
>
>> ss <- "7/2/1982312.7212.0618.397471390.4
> + 7/6/1982311208.4518.227521392.2
> + 7/7/1982306.7206.4118.327381385
> + 7/8/1982313.5207.1918.567221392.6
> + 7/13/1982352.5205.7918.857301485.7
> + 7/14/1982352.7206.2718.757211494.9
> + 7/15/1982350.2207.1218.717121491.6
> + 7/20/1982347.7205.3218.626611508.8
> + 7/21/1982366.5204.6618.776541575.6
> + 7/26/1982352.2208.418.526541554.9
> + 7/27/1982351.2212.1718.516591523.6
> + 7/28/1982347213.9618.226541499.3
> + 7/30/1982342.9215.8318.066581467.9
> + 8/3/1982349.2216.3718.147281536.6
> + "
>> ss1 <- textConnection(ss)
>> read.zoo(ss1, format = "%m/%d/%Y", header = FALSE)
> Error in read.zoo(ss1, format = "%m/%d/%Y", header = FALSE) :
>  index contains NAs
>
>
> Any other suggestion?
>
>
>
> Gabor Grothendieck wrote:
>>
>> The format for the year should be %Y, not %y; however, without a
>> reproducible
>> example (see last line to every message on R help) we can't be sure
>> that that is the whole story.
>>
>> On Wed, Jul 29, 2009 at 3:00 AM, Bogaso<bogaso.christofer at gmail.com>
>> wrote:
>>>
>>> I have a time series dataset, saved in a csv file. However
>>> date-formatting is
>>> :
>>>
>>> 7/2/1982
>>> 7/6/1982
>>> 7/7/1982
>>> 7/8/1982
>>> 7/13/1982
>>> 7/14/1982
>>>
>>> However if I use following zoo-code, it is not reading data:
>>>
>>> read.zoo(file="F:/data.csv", format="%m/%d/%y", header=F)
>>>
>>> Error is
>>> Error in read.zoo(file ="F:/data.csv", format = "%m/%d/%y",  :
>>>  index contains NAs
>>>
>>> Here I have the mandate to keep date formating in abovementioned way. Can
>>> anyone please tell me what to do here?
>>>
>>> Regards,
>>>
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Importing-time-series-tp24713580p24713580.html
>>> Sent from the R help mailing list archive at Nabble.com.
>>>
>>> ______________________________________________
>>> 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.
>>>
>>
>> ______________________________________________
>> 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.
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Importing-time-series-tp24713580p24714603.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list