Re: [R] Sum data according to date in sequence

2023-11-04 Thread roslinazairimah zakaria
Hi all, Thank you very much. I learn a lot from your suggested solution. On Sun, Nov 5, 2023 at 12:56 AM Rui Barradas wrote: > Às 01:49 de 03/11/2023, roslinazairimah zakaria escreveu: > > Hi all, > > > > This is the data: > > > >> dput(head(dt1,20))structure(list(StationName = c("PALO ALTO CA

Re: [R] Sum data according to date in sequence

2023-11-04 Thread avi.e.gross
discussing whether, especially for larger data sets, there are ways that could be more efficient. -Original Message- From: R-help On Behalf Of Rui Barradas Sent: Saturday, November 4, 2023 12:56 PM To: roslinazairimah zakaria ; jim holtman Cc: r-help mailing list Subject: Re: [R] Sum data ac

Re: [R] Sum data according to date in sequence

2023-11-04 Thread Rui Barradas
Às 01:49 de 03/11/2023, roslinazairimah zakaria escreveu: Hi all, This is the data: dput(head(dt1,20))structure(list(StationName = c("PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO

Re: [R] Sum data according to date in sequence

2023-11-03 Thread roslinazairimah zakaria
Hi Jim, Yes, that is exactly what I am trying to do. Once I get that, I want to plot time series data. Thank you very much Jim. On Fri, Nov 3, 2023 at 11:58 PM jim holtman wrote: > Is this what you are after? > > library(tidyverse) > > > library(lubridate) > > input <- structure(list(StationNam

Re: [R] Sum data according to date in sequence

2023-11-03 Thread jim holtman
Is this what you are after? library(tidyverse) library(lubridate) input <- structure(list(StationName = c("PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1

Re: [R] Sum data according to date in sequence

2023-11-03 Thread Jeff Newmiller via R-help
Cbind is not a very good tool for adding columns to a data frame. Either use explicit column referencing like dt1$x <- new_data_vector but you do have to make sure the new data vector has the same number of values and in the same order as the other data in dt1. The transition from multiple rec

Re: [R] Sum data according to date in sequence

2023-11-03 Thread roslinazairimah zakaria
Hi, I tried this: # extract date from the time stamp dt1 <- cbind(as.Date(dt$EndDate, format="%m/%d/%Y"), dt$EnergykWh) head(dt1) colnames(dt1) <- c("date", "EnergykWh") and my dt1 becomes these, the dates are replace by numbers. dt1 <- cbind(as.Date(dt$EndDate, format="%m/%d/%Y"), dt$EnergykWh) d

Re: [R] Sum data according to date in sequence

2023-11-02 Thread roslinazairimah zakaria
Thank you very much for your help. It is very much appreciated. On Fri, Nov 3, 2023 at 7:23 AM roslinazairimah zakaria wrote: > Dear all, > > I have this set of data. I would like to sum the EnergykWh according date > sequences. > > > head(dt1,20) StationName date time En

Re: [R] Sum data according to date in sequence

2023-11-02 Thread roslinazairimah zakaria
Hi all, This is the data: > dput(head(dt1,20))structure(list(StationName = c("PALO ALTO CA / CAMBRIDGE > #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",

Re: [R] Sum data according to date in sequence

2023-11-02 Thread jim holtman
How about send a 'dput' of some sample data. My guess is that your date is 'character' and not 'Date'. Thanks Jim Holtman *Data Munger Guru* *What is the problem that you are trying to solve?Tell me what you want to do, not how you want to do it.* On Thu, Nov 2, 2023 at 4:24 PM roslinazairim

Re: [R] Sum data according to date in sequence

2023-11-02 Thread Christopher W. Ryan via R-help
date appears to be a character variable, and R is treating it as such. str(dt1) might give you some insight. Or the dplyr equivalent glimpse(dt1) I think R did what you asked, but if you want to be able to order records by date, in temporal order, you need to tell R that it is a date: library