The actual  "date" col is in yyyy-mm-dd format, and when I apply this code
to my actual data, it mess up the order


On Wed, May 29, 2013 at 11:37 AM, arun <smartpink...@yahoo.com> wrote:

>
>
> Hi,
> May be I misunderstood your question:
> dat<- read.table(text="
> Date    Time  Var
> 1            1        2
> 1          1        4
> 1          1        5
> 1          2          8
> 1          2          8
> 1        2          9
> 2        1            3
> 2        1              4
> 2        1            4
> ",sep="",header=TRUE)
> dat$UniqueID <- paste(dat$Date,dat$Time, sep = '_')
>  aggregate(dat$Var,list(dat$UniqueID),sum) #isn't this the correct order
> #  Group.1  x
> #1     1_1 11
> #2     1_2 25
> #3     2_1 11
> library(plyr)
> ddply(dat,.(UniqueID),summarize,Var=sum(Var))
> #  UniqueID Var
> #1      1_1  11
> #2      1_2  25
> #3      2_1  11
> A.K.
>
>
>
> ----- Original Message -----
> From: Ye Lin <ye...@lbl.gov>
> To: R help <r-help@r-project.org>
> Cc:
> Sent: Wednesday, May 29, 2013 2:23 PM
> Subject: [R] combine two columns into one
>
> Hey all!
>
> I have a time series dataset like this:
>
> Date    Time   Var
> 1            1        2
> 1           1        4
> 1           1         5
> 1          2          8
> 1          2          8
> 1         2           9
> 2        1            3
> 2        1              4
> 2        1            4
>
> I created a unique id for each row:
> dat$UniqueID <- paste(dat$Date,dat$Time, sep = '_')
>
> then
>
> aggregate(dat$Var, list(dat$UniqueID), sum)
>
> however the final output is not in ideal order I look for (I simply this
> example provided above).I would like to have order like this:
>
> 1_1
> 1_2
> 2_1
>
> Thanks for your help!
>
>     [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to