Zilefac Elvis
2014-Apr-05 04:02 UTC
[R] Aggregate time series from daily to monthly by date and site
Hi, I have daily data arranged by date and site. Keeping the number of columns as there are, I will like to aggregate (FUN=mean) from daily to monthly the following data (only part is shown here) which starts in 1971 and ends in 1980. ? ? Year Month Day Site Sim001 Sim002 Sim003 Sim004 1 ? 1971 ? ? 1 ? 1 GGG1 ? 8.58 -12.67 ? 4.45 ?-1.31 2 ? 1971 ? ? 1 ? 1 GGG2 ?11.82 ?-9.94 ?-3.37 ? 4.94 3 ? 1971 ? ? 1 ? 1 GGG3 ? 7.72 -11.94 ?-1.17 ? 4.70 4 ? 1971 ? ? 1 ? 1 GGG4 ? 8.93 -10.81 ? 4.66 ? 2.88 5 ? 1971 ? ? 1 ? 1 GGG5 ? 9.82 ?-6.78 ?-4.19 ?-0.01 6 ? 1971 ? ? 1 ? 1 GGG6 ?13.93 ?-3.39 ?-3.84 ? 1.83 7 ? 1971 ? ? 1 ? 1 GGG7 ?10.94 ?-7.58 ? 1.74 ?-7.51 8 ? 1971 ? ? 1 ? 1 GGG8 ? 5.07 -16.09 ? 1.26 ? 1.12 9 ? 1971 ? ? 1 ? 1 GGG9 ?11.13 ?-9.96 ?-7.06 ? 5.25 10 ?1971 ? ? 1 ? 1 GG10 ? 7.66 ?-8.68 ?-2.65 ? 5.25 11 ?1971 ? ? 1 ? 1 GG11 ? 1.06 ? 6.14 ?-4.88 ? 3.78 12 ?1971 ? ? 1 ? 1 GG12 ?14.93 -12.43 ?-4.06 ? 4.94 13 ?1971 ? ? 1 ? 1 GG13 ? 7.56 -10.81 ?-2.32 ? 2.32 14 ?1971 ? ? 1 ? 1 GG14 ? 6.18 ?-7.58 ?-1.64 ? 9.83 15 ?1971 ? ? 1 ? 1 GG15 ?10.96 ?-0.62 ? 0.56 ?-1.59 16 ?1971 ? ? 1 ? 1 GG16 ? 4.94 ? 1.52 ? 0.31 ? 6.45 17 ?1971 ? ? 1 ? 1 GG17 ? 0.79 ? 0.83 ?-0.35 ? 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? 1 ? 1 GG99 ?-3.11 ? 3.21 ?-2.89 ?-4.38 100 1971 ? ? 1 ? 1 G100 ? 2.45 ? 0.21 ?-6.41 ? 0.67 Thanks for your useful solution. Atem.
Jeff Newmiller
2014-Apr-05 04:53 UTC
[R] Aggregate time series from daily to monthly by date and site
You have been around long enough that we should not have to tell you how to provide data in a reproducible manner... read ?dput. --------------------------------------------------------------------------- Jeff Newmiller The ..... ..... Go Live... DCN:<jdnewmil at dcn.davis.ca.us> 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. On April 4, 2014 9:02:03 PM PDT, Zilefac Elvis <zilefacelvis at yahoo.com> wrote:>Hi, >I have daily data arranged by date and site. Keeping the number of >columns as there are, I will like to aggregate (FUN=mean) from daily to >monthly the following data (only part is shown here) which starts in >1971 and ends in 1980. > >? ? Year Month Day Site Sim001 Sim002 Sim003 Sim004 >1 ? 1971 ? ? 1 ? 1 GGG1 ? 8.58 -12.67 ? 4.45 ?-1.31 >2 ? 1971 ? ? 1 ? 1 GGG2 ?11.82 ?-9.94 ?-3.37 ? 4.94 >3 ? 1971 ? ? 1 ? 1 GGG3 ? 7.72 -11.94 ?-1.17 ? 4.70 >4 ? 1971 ? ? 1 ? 1 GGG4 ? 8.93 -10.81 ? 4.66 ? 2.88 >5 ? 1971 ? ? 1 ? 1 GGG5 ? 9.82 ?-6.78 ?-4.19 ?-0.01 >6 ? 1971 ? ? 1 ? 1 GGG6 ?13.93 ?-3.39 ?-3.84 ? 1.83 >7 ? 1971 ? ? 1 ? 1 GGG7 ?10.94 ?-7.58 ? 1.74 ?-7.51 >8 ? 1971 ? ? 1 ? 1 GGG8 ? 5.07 -16.09 ? 1.26 ? 1.12 >9 ? 1971 ? ? 1 ? 1 GGG9 ?11.13 ?-9.96 ?-7.06 ? 5.25 >10 ?1971 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51 >90 ?1971 ? ? 1 ? 1 GG90 ?-5.90 ? 2.54 ? 8.87 ? 9.46 >91 ?1971 ? ? 1 ? 1 GG91 ?-4.73 ? 2.88 ? 7.23 ? 8.55 >92 ?1971 ? ? 1 ? 1 GG92 ?-8.13 ? 6.79 ? 8.07 ? 6.71 >93 ?1971 ? ? 1 ? 1 GG93 ?-7.67 ? 5.50 ? 2.77 ? 7.36 >94 ?1971 ? ? 1 ? 1 GG94 ? 3.73 ?-2.36 ? 9.61 ?10.96 >95 ?1971 ? ? 1 ? 1 GG95 ?-2.40 ? 4.18 ?-1.10 ? 3.47 >96 ?1971 ? ? 1 ? 1 GG96 ? 1.46 ?-0.13 ?-2.05 ?-1.99 >97 ?1971 ? ? 1 ? 1 GG97 ?-4.71 ? 5.68 ? 6.39 ? 5.75 >98 ?1971 ? ? 1 ? 1 GG98 ? 0.33 ? 1.82 ? 6.60 ? 1.56 >99 ?1971 ? ? 1 ? 1 GG99 ?-3.11 ? 3.21 ?-2.89 ?-4.38 >100 1971 ? ? 1 ? 1 G100 ? 2.45 ? 0.21 ?-6.41 ? 0.67 > > > >Thanks for your useful solution. >Atem. > >______________________________________________ >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.
Zilefac Elvis
2014-Apr-05 05:37 UTC
[R] Aggregate time series from daily to monthly by date and site
Hi, I have daily data arranged by date and site. Keeping the number of columns as there are, I will like to aggregate (FUN=mean) from daily to monthly the following data (only part is shown here) which starts in 1971 and ends in 1980. structure(list(Year = c(1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971, 1971), Month = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), Day = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), Site = c("GGG1", "GGG2", "GGG3", "GGG4", "GGG5", "GGG6", "GGG7", "GGG8", "GGG9", "GG10", "GG11", "GG12", "GG13", "GG14", "GG15", "GG16", "GG17", "GG18", "GG19", "GG20", "GG21", "GG22", "GG23", "GG24", "GG25", "GG26", "GG27", "GG28", "GG29", "GG30", "GG31", "GG32", "GG33", "GG34", "GG35", "GG36", "GG37", "GG38", "GG39", "GG40", "GG41", "GG42", "GG43", "GG44", "GG45", "GG46", "GG47", "GG48", "GG49", "GG50", "GG51", "GG52", "GG53", "GG54", "GG55", "GG56", "GG57", "GG58", "GG59", "GG60", "GG61", "GG62", "GG63", "GG64", "GG65", "GG66", "GG67", "GG68", "GG69", "GG70", "GG71", "GG72", "GG73", "GG74", "GG75", "GG76", "GG77", "GG78", "GG79", "GG80", "GG81", "GG82", "GG83", "GG84", "GG85", "GG86", "GG87", "GG88", "GG89", "GG90", "GG91", "GG92", "GG93", "GG94", "GG95", "GG96", "GG97", "GG98", "GG99", "G100" ), Sim001 = c(8.58, 11.82, 7.72, 8.93, 9.82, 13.93, 10.94, 5.07, 11.13, 7.66, 1.06, 14.93, 7.56, 6.18, 10.96, 4.94, 0.79, 4.91, 0.68, 4.5, 3.13, 2.91, -2.27, 8.18, 3.87, 5.1, 7.23, 8.55, 1.39, 6.85, 4.25, -0.24, 9.86, 9.92, 5.11, 6.14, 8.14, 7.52, 4.19, 1.02, -2.43, 6.85, 4.94, 8.11, 7.34, 10.56, -6.52, 2.66, -4.89, 0.11, 3.9, 3.87, 2.55, -0.2, 5.09, -2.4, 1.32, 3.49, 4.93, -9.58, 9.08, 2.85, 7.71, 4.5, 0.99, 8.72, 12.45, 8.83, 8.94, 5.05, 9.82, 11.72, 1.21, 7.92, 3.45, 1.34, 8.25, 2.92, 2.1, -3.19, 4.75, -0.3, 1.69, 3.31, 5.18, 2.43, 3.02, -5.31, -6.7, -5.9, -4.73, -8.13, -7.67, 3.73, -2.4, 1.46, -4.71, 0.33, -3.11, 2.45), Sim002 = c(-12.67, -9.94, -11.94, -10.81, -6.78, -3.39, -7.58, -16.09, -9.96, -8.68, 6.14, -12.43, -10.81, -7.58, -0.62, 1.52, 0.83, -3.29, -0.5, 1.14, 3.35, 1.1, -5.25, 2, -4.09, 2.28, 2.46, 5.64, 4.64, -12.11, -2.21, -16.54, -7.38, -16.33, -7.63, -11.61, -12.78, -12.86, -9.99, 4.84, -13.75, -12.33, -13.43, -21.13, -12.63, -3.16, 1.61, -2.36, 5.54, 3.59, 1.23, -0.25, -1.49, -1.65, 0.9, -2.29, -2.35, -2.01, -2.07, 1.37, -0.64, 4.75, 3.02, 5.44, 3.76, 5.16, 2.54, 4.11, 5.03, -1.12, 4.53, -0.15, -4.98, 0.85, -3.04, -0.06, -3.01, -1.1, 4.02, 1.77, -3.36, 1.56, -1.63, 1.12, -2.39, -2.05, 4.51, 1.52, -0.61, 2.54, 2.88, 6.79, 5.5, -2.36, 4.18, -0.13, 5.68, 1.82, 3.21, 0.21), Sim003 = c(4.45, -3.37, -1.17, 4.66, -4.19, -3.84, 1.74, 1.26, -7.06, -2.65, -4.88, -4.06, -2.32, -1.64, 0.56, 0.31, -0.35, -5.69, 3.35, 4.84, 3.62, 0.77, -3.05, -0.42, -2.55, 1.34, 2.89, 3.09, 9.79, 4.98, 9.59, 4.99, 11.77, 13.07, 0.41, 10.38, 11.01, 3.43, 6.08, 0.55, 6.49, 2.85, 11.17, 11.32, -0.89, -0.48, 10.8, 1.86, 6.63, 5.14, 4.13, 8.72, 15.01, 4.78, 5.56, 5.69, 10.39, 8.99, 6.95, 10.59, 3.92, 3.4, 3.95, 0.87, 2.28, 1.11, 4.36, 6.21, 1.73, 2.5, 4.19, 1.85, 8.65, 6.24, 7.82, 7.43, 5.19, -1.71, -3.16, -2.66, -7, -2.08, 0.36, 8.61, 3.22, 7.99, -1.19, 11.38, 10.2, 8.87, 7.23, 8.07, 2.77, 9.61, -1.1, -2.05, 6.39, 6.6, -2.89, -6.41), Sim004 = c(-1.31, 4.94, 4.7, 2.88, -0.01, 1.83, -7.51, 1.12, 5.25, 5.25, 3.78, 4.94, 2.32, 9.83, -1.59, 6.45, 4.26, 3.1, 5.5, 6.94, 2.76, 5.1, 1.95, 15.13, -9.18, 2.88, 4.28, -5.01, -0.27, 1.91, -1.46, -0.6, -8.99, -8.79, -3.09, -7.09, -5.2, -7.55, -4.04, -3.8, -10.66, -6.34, -3.62, -8.49, -2.29, 0.38, 5.25, 8.6, 5.83, 8.94, 9.86, 4.62, 4.33, 10.15, 7.87, 9.07, 0.04, 2.85, 6, 4.54, 13.5, 12.39, 11.79, 6.29, 15.45, 15.82, 19.79, 13.12, 6.5, -4.63, 1.79, -0.8, 1.29, 8.88, 1.28, 6.55, 5.78, 5.46, 2.83, 8, 6.25, 4.94, 5.01, 5.32, 2.95, 7.46, 5.71, -3.51, 3.51, 9.46, 8.55, 6.71, 7.36, 10.96, 3.47, -1.99, 5.75, 1.56, -4.38, 0.67)), .Names = c("Year", "Month", "Day", "Site", "Sim001", "Sim002", "Sim003", "Sim004"), row.names = c(NA, 100L), class = "data.frame") Thanks for your useful solution. Atem. [[alternative HTML version deleted]]