construct a data set

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

construct a data set

nandan amar
Hi,
i want to construct a data set similar to  "AirPassengers".
Its attributes are following.

> attributes(AirPassengers)
$tsp
[1] 1949.000 1960.917   12.000

$class
[1] "ts"


How Can I construct a data set similar to it having same class and attributes.
Thanks
--
Amar Kumar Nandan
✉:[hidden email]
http://aknandan.co.nr

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: construct a data set

Michael Weylandt
Well, depending on how similar you want/need it to be, you could simply make a copy and directly modify it as desired;

AP2 <- AirPassengers
AP2$tsp <- c(3,4,5) # or whatever

It's quick and dirty but sounds like it works for you. Write back if this isn't clear or if you care to provide more info on what you want to do.

Cheers and good luck getting started in R.

Michael Weylandt

On Jul 28, 2011, at 5:27 AM, nandan amar <[hidden email]> wrote:

> Hi,
> i want to construct a data set similar to  "AirPassengers".
> Its attributes are following.
>
>> attributes(AirPassengers)
> $tsp
> [1] 1949.000 1960.917   12.000
>
> $class
> [1] "ts"
>
>
> How Can I construct a data set similar to it having same class and attributes.
> Thanks
> --
> Amar Kumar Nandan
> ✉:[hidden email]
> http://aknandan.co.nr
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: construct a data set

nandan amar
Thanks a lot Michael,

I wanted to create similar data set for weekly data, for say 2 weeks
>data<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
now i want to put data[ ] in the same structure as AirPassengers i.e.
instead of 12x12  matrix AP2 should be a 2x7 matrix and with same
attributes as AirPassengers
I tried like following
> AP2 <- AirPassengers
>AP2$tsp <- c(1,2,7)

But i dont think even AirPassengers$tsp exist

Also AirPassengers is a 1D array 1:144
may be some thing more is required.
thanks.

On Thu, Jul 28, 2011 at 5:42 PM, R. Michael Weylandt
<[hidden email]> <[hidden email]> wrote:

> Well, depending on how similar you want/need it to be, you could simply make a copy and directly modify it as desired;
>
> AP2 <- AirPassengers
> AP2$tsp <- c(3,4,5) # or whatever
>
> It's quick and dirty but sounds like it works for you. Write back if this isn't clear or if you care to provide more info on what you want to do.
>
> Cheers and good luck getting started in R.
>
> Michael Weylandt
>
> On Jul 28, 2011, at 5:27 AM, nandan amar <[hidden email]> wrote:
>
>> Hi,
>> i want to construct a data set similar to  "AirPassengers".
>> Its attributes are following.
>>
>>> attributes(AirPassengers)
>> $tsp
>> [1] 1949.000 1960.917   12.000
>>
>> $class
>> [1] "ts"
>>
>>
>> How Can I construct a data set similar to it having same class and attributes.
>> Thanks
>> --
>> Amar Kumar Nandan
>> ✉:[hidden email]
>> http://aknandan.co.nr
>>
>> ______________________________________________
>> [hidden email] 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.
>



--
Amar Kumar Nandan
Karnataka, India, 560100

☎:+91-9019054471
✉:[hidden email]
http://aknandan.co.nr

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: construct a data set

Michael Weylandt
I'm a little confused: what is making data = 1:14 into a 12x12 matrix and
how is that related to AirPassengers?

Best I understand it, tsp is a little fun and included as an S legacy. If
you want to access tsp directly, take a look at the tsp(x) function (and the
associated hasTsp(x) function). If AirPassengers has a tsp attribute, AP2
will have the same tsp, but it's not something I'd recommend directly
playing with -- it's slightly unweildy. Though, if you really do want to
work on an attribute level, the attr function lets you access & change
attributes directly.

More generally, can I ask what you are trying to do: it looks like you are
trying to work with a time series of data (hence the ts class) but what are
the observations supposed to be: individual numbers or arrays? I.e., is the
third observation the number "3" or is it a whole set of observations, like
ID numbers of everyone who flew on a given day.  If the number of
observations at each time step is constant, it might make sense to run
multiple time series with the same time index (eg. the mts sets of
behavior).

I'm personally a big fan of the xts time series, even though it's a little
finance oriented, as it has some great additions to R's native ts class. If
you are trying to aggregate daily data to weekly, the to.weekly() function
will handle that for you; you'll probably want the OHLC=F option.

Hope something in this helps,

Michael Weylandt

On Thu, Jul 28, 2011 at 10:14 AM, nandan amar <[hidden email]> wrote:

> Thanks a lot Michael,
>
> I wanted to create similar data set for weekly data, for say 2 weeks
> >data<-c(1,2,3,4,5,6,7,8,9,10,11,12,13,14)
> now i want to put data[ ] in the same structure as AirPassengers i.e.
> instead of 12x12  matrix AP2 should be a 2x7 matrix and with same
> attributes as AirPassengers
> I tried like following
> > AP2 <- AirPassengers
> >AP2$tsp <- c(1,2,7)
>
> But i dont think even AirPassengers$tsp exist
>
> Also AirPassengers is a 1D array 1:144
> may be some thing more is required.
> thanks.
>
> On Thu, Jul 28, 2011 at 5:42 PM, R. Michael Weylandt
> <[hidden email]> <[hidden email]> wrote:
> > Well, depending on how similar you want/need it to be, you could simply
> make a copy and directly modify it as desired;
> >
> > AP2 <- AirPassengers
> > AP2$tsp <- c(3,4,5) # or whatever
> >
> > It's quick and dirty but sounds like it works for you. Write back if this
> isn't clear or if you care to provide more info on what you want to do.
> >
> > Cheers and good luck getting started in R.
> >
> > Michael Weylandt
> >
> > On Jul 28, 2011, at 5:27 AM, nandan amar <[hidden email]> wrote:
> >
> >> Hi,
> >> i want to construct a data set similar to  "AirPassengers".
> >> Its attributes are following.
> >>
> >>> attributes(AirPassengers)
> >> $tsp
> >> [1] 1949.000 1960.917   12.000
> >>
> >> $class
> >> [1] "ts"
> >>
> >>
> >> How Can I construct a data set similar to it having same class and
> attributes.
> >> Thanks
> >> --
> >> Amar Kumar Nandan
> >> ✉:[hidden email]
> >> http://aknandan.co.nr
> >>
> >> ______________________________________________
> >> [hidden email] 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.
> >
>
>
>
> --
> Amar Kumar Nandan
> Karnataka, India, 560100
>
> ☎:+91-9019054471
> ✉:[hidden email]
> http://aknandan.co.nr
>
        [[alternative HTML version deleted]]


______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: construct a data set

Eik Vettorazzi
In reply to this post by nandan amar
Hi Amar,
you might have a look at ?ts, which creates time-series objects (as
AirPassengers actually is, see class(AirPassengers)).

hth

Am 28.07.2011 11:27, schrieb nandan amar:

> Hi,
> i want to construct a data set similar to  "AirPassengers".
> Its attributes are following.
>
>> attributes(AirPassengers)
> $tsp
> [1] 1949.000 1960.917   12.000
>
> $class
> [1] "ts"
>
>
> How Can I construct a data set similar to it having same class and attributes.
> Thanks
> --
> Amar Kumar Nandan
> ✉:[hidden email]
> http://aknandan.co.nr
>
> ______________________________________________
> [hidden email] 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.


--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: construct a data set

nandan amar
Dear Michael and Vettorazzi,
Thanks.
It was really helpful.
I got the desired answer .
Actually I had some weekly data and i wanted to put in ts class for
some time series related test.
Thanks a lot :)

On Thu, Jul 28, 2011 at 8:20 PM, Eik Vettorazzi
<[hidden email]> wrote:

> Hi Amar,
> you might have a look at ?ts, which creates time-series objects (as
> AirPassengers actually is, see class(AirPassengers)).
>
> hth
>
> Am 28.07.2011 11:27, schrieb nandan amar:
>> Hi,
>> i want to construct a data set similar to  "AirPassengers".
>> Its attributes are following.
>>
>>> attributes(AirPassengers)
>> $tsp
>> [1] 1949.000 1960.917   12.000
>>
>> $class
>> [1] "ts"
>>
>>
>> How Can I construct a data set similar to it having same class and attributes.
>> Thanks
>> --
>> Amar Kumar Nandan
>> ✉:[hidden email]
>> http://aknandan.co.nr
>>
>> ______________________________________________
>> [hidden email] 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.
>
>
> --
> Eik Vettorazzi
> Institut für Medizinische Biometrie und Epidemiologie
> Universitätsklinikum Hamburg-Eppendorf
>
> Martinistr. 52
> 20246 Hamburg
>
> T ++49/40/7410-58243
> F ++49/40/7410-57790
>



--
Amar Kumar Nandan
Karnataka, India, 560100

☎:+91-9019054471

✉:[hidden email]

http://aknandan.co.nr

______________________________________________
[hidden email] 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.