Quantcast

Simple matrix transformation question

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Simple matrix transformation question

Henry
I know this is likely very simple.  I want to change a matrix that was given to me not sorted by timestamp to sorted by timestamp.   It was sorted by CRAH_Name.  There are 264k records initially.  The CRAH names start at 11 and go to 98 but there are a number of missing values (CRAH_Name), total approx. 50.

A small example of the given matrix

Time_Stamp Power CRAH_Name
4/16/2012 00:00 3.4862 11
4/16/2012 00:01 3.4862 11
4/16/2012 00:02 3.61035 11
4/16/2012 00:03 3.57215 11
4/16/2012 00:04 3.6008 11
4/16/2012 00:05 3.64855 11
4/16/2012 00:06 3.64855 11
4/16/2012 00:07 3.6008 11
4/16/2012 00:08 3.639 11
4/16/2012 00:09 3.6581 11
4/16/2012 00:10 3.6963 11
4/16/2012 00:00 2.618646 98   (timestamping starts over again at 00:00)
4/16/2012 00:01 2.195102 98
4/16/2012 00:02 2.758223 98
4/16/2012 00:03 2.796727 98
4/16/2012 00:04 2.652337 98
4/16/2012 00:05 2.233606 98
4/16/2012 00:06 2.811166 98
4/16/2012 00:07 2.690841 98
4/16/2012 00:08 2.406874 98
4/16/2012 00:09 2.811166 98
4/16/2012 00:10 2.286549 98

I want to transform into a dataframe that looks like this..
CRAH Name             11                       12                     13............                    98
timestamp ..01        power value   power value  power value ...........power value
timestamp ..02        power value   power value  power value ...........power value
timestamp ..03        power value   power value  power value ...........power value

This is how I'm used to dealing with time series data.

Thanks very much for any help.  I would like to use standard R function if not too complicated.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Simple matrix transformation question

Henry
I didn't say how I would read it in... I assume just read in using read.table but I didn't try that.
So I guess that is another part of the question.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Simple matrix transformation question

Jeff Newmiller
In reply to this post by Henry
library(reshape2)
?dcast
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

Henry <[hidden email]> wrote:

>I know this is likely very simple.  I want to change a matrix that was
>given
>to me not sorted by timestamp to sorted by timestamp.   It was sorted
>by
>CRAH_Name.  There are 264k records initially.  The CRAH names start at
>11
>and go to 98 but there are a number of missing values (CRAH_Name),
>total
>approx. 50.
>
>A small example of the given matrix
>
>Time_Stamp Power CRAH_Name
>4/16/2012 00:00 3.4862 11
>4/16/2012 00:01 3.4862 11
>4/16/2012 00:02 3.61035 11
>4/16/2012 00:03 3.57215 11
>4/16/2012 00:04 3.6008 11
>4/16/2012 00:05 3.64855 11
>4/16/2012 00:06 3.64855 11
>4/16/2012 00:07 3.6008 11
>4/16/2012 00:08 3.639 11
>4/16/2012 00:09 3.6581 11
>4/16/2012 00:10 3.6963 11
>4/16/2012 00:00 2.618646 98   (timestamping starts over again at 00:00)
>4/16/2012 00:01 2.195102 98
>4/16/2012 00:02 2.758223 98
>4/16/2012 00:03 2.796727 98
>4/16/2012 00:04 2.652337 98
>4/16/2012 00:05 2.233606 98
>4/16/2012 00:06 2.811166 98
>4/16/2012 00:07 2.690841 98
>4/16/2012 00:08 2.406874 98
>4/16/2012 00:09 2.811166 98
>4/16/2012 00:10 2.286549 98
>
>I want to transform into a dataframe that looks like this..
>CRAH Name             11                       12                    
>13............                    98
>timestamp ..01        power value   power value  power value
>...........power value
>timestamp ..02        power value   power value  power value
>...........power value
>timestamp ..03        power value   power value  power value
>...........power value
>
>This is how I'm used to dealing with time series data.
>
>Thanks very much for any help.  I would like to use standard R function
>if
>not too complicated.
>
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Simple-matrix-transformation-question-tp4585044p4585044.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>[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
|  
Report Content as Inappropriate
star

Re: Simple matrix transformation question

Henry
Jeff,
Thanks we are looking at that (reshape2 and dcast) now.
-Henry
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Simple matrix transformation question

Henry
In reply to this post by Jeff Newmiller
Jeff,
Thanks we are looking at that (reshape2 and dcast) now.
-Henry
Loading...