Help on Aggregation

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

Help on Aggregation

Emeka Don
Dear All,
1.I have been trying to aggregate my data but I have not been getting it
correctly. In the data I want to convert hourly data into daily averages.
Here is a sample of the data:
Neph_no Date Time Temp_C   Pressure_kPa RH
9   2014/03/28  10:00:00 38.4 95.9 29.7
9   2014/03/28  11:00:00 37.8 95.8 29.2
9   2014/03/28  12:00:00 36.7 95.8 35.1
9   2014/03/28  13:00:00 35.4 95.8 38.9
9   2014/03/28  14:00:00 34.1 95.8 44
9   2014/03/28  15:00:00 32.7 95.9 52.9
9   2014/03/28  16:00:00 31.8 96 55.1
9   2014/03/28  17:00:00 31.2 96 57.8
9   2014/03/28  18:00:00 30.6 96.1 62.1
9   2014/03/28  19:00:00 29.8 96.1 68.1
9   2014/03/28  20:00:00 29.1 96.1 69.5
9   2014/03/28  21:00:00 28.6 96 68.3
9   2014/03/28  22:00:00 28 96 71.9
9   2014/03/28  23:00:00 27.4 95.9 76.4
9   2014/03/29  00:00:00 27 96 80.6
9   2014/03/29  01:00:00 27.1 96 80.4
9   2014/03/29  02:00:00 27 96.1 80.5
9   2014/03/29  03:00:00 27.8 96.1 78.1
9   2014/03/29  04:00:00 30.4 96.2 66.8
9   2014/03/29  05:00:00 33.7 96.3 54
9   2014/03/29  06:00:00 36.3 96.3 45
9   2014/03/29  07:00:00 37.7 96.3 38.8
9   2014/03/29  08:00:00 38.7 96.3 34.7
9   2014/03/29  09:00:00 38.9 96.1 32.6
9   2014/03/29  10:00:00 39.4 96 30.2
9   2014/03/29  11:00:00 38.9 95.9 31.5
9   2014/03/29  12:00:00 38.2 95.8 33.8
9   2014/03/29  13:00:00 37.4 95.8 35.4
9   2014/03/29  14:00:00 35.8 95.9 39.5
9   2014/03/29  15:00:00 33.9 96 46.9
9   2014/03/29  16:00:00 31.4 96.1 59.8
9   2014/03/29  17:00:00 29.4 96.3 72.9
9   2014/03/29  18:00:00 29 96.3 69.6
9   2014/03/29  19:00:00 26.5 96.2 81.7
9   2014/03/29  20:00:00 27 96.1 82.9
9   2014/03/29  21:00:00 27.5 96.1 81.7
9   2014/03/29  22:00:00 27.4 96 82.6
9   2014/03/29  23:00:00 27.3 96 83.1
9   2014/03/30  00:00:00 27.1 96 84.5
9   2014/03/30  01:00:00 27.6 96.1 81.8
9   2014/03/30  02:00:00 27.8 96.1 81

2. I have some data of about 6100 rows and 6 columns, but anytime i read it
into R, it removes the header and a large chunk of the data.( i:e it will
import from row 3550-6099). This is the code i used for it
"met_data=read.csv(file.choose(),header=TRUE)", so, how do I read the
entire data into R without missing some?
Thank you.

--
Onyeuwaoma Nnaemeka Dom

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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: Help on Aggregation

PIKAL Petr
Hi

The first question is simple. You should use aggregate and cut but first you need to transfer your data to date/time format by strptime.

test<-read.table("clipboard", header=T)
test$cas<-strptime(paste(test$Date, test$Time), format="%Y/%m/%d %H:%M:%S")

Below is the data.

aggregate(test[,4:6], list(cut(test$cas, "days")), mean, na.rm=T)
     Group.1   Temp_C Pressure_kPa       RH
1 2014-03-28 32.25714     95.94286 54.21429
2 2014-03-29 32.23750     96.09167 59.29583
3 2014-03-30 27.35000     96.05000 83.15000

The second one is difficult if impossible to answer.

read.csv(file.choose(),header=TRUE)
This seems to be OK. So my guess is that the original file is not csv or that it has some hidden characters elsewhere.

Cheers
Petr

dput(test)
structure(list(Neph_no = c(9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L
), Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L), .Label = c("2014/03/28",
"2014/03/29", "2014/03/30"), class = "factor"), Time = structure(c(11L,
12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L,
1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L,
15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 1L, 2L, 3L), .Label = c("00:00:00",
"01:00:00", "02:00:00", "03:00:00", "04:00:00", "05:00:00", "06:00:00",
"07:00:00", "08:00:00", "09:00:00", "10:00:00", "11:00:00", "12:00:00",
"13:00:00", "14:00:00", "15:00:00", "16:00:00", "17:00:00", "18:00:00",
"19:00:00", "20:00:00", "21:00:00", "22:00:00", "23:00:00"), class = "factor"),
    Temp_C = c(38.4, 37.8, 36.7, 35.4, 34.1, 32.7, 31.8, 31.2,
    30.6, 29.8, 29.1, 28.6, 28, 27.4, 27, 27.1, 27, 27.8, 30.4,
    33.7, 36.3, 37.7, 38.7, 38.9, 39.4, 38.9, 38.2, 37.4, 35.8,
    33.9, 31.4, 29.4, 29, 26.5, 27, 27.5, 27.4, 27.3, 27.1, 27.6,
    27.8), Pressure_kPa = c(95.9, 95.8, 95.8, 95.8, 95.8, 95.9,
    96, 96, 96.1, 96.1, 96.1, 96, 96, 95.9, 96, 96, 96.1, 96.1,
    96.2, 96.3, 96.3, 96.3, 96.3, 96.1, 96, 95.9, 95.8, 95.8,
    95.9, 96, 96.1, 96.3, 96.3, 96.2, 96.1, 96.1, 96, 96, 96,
    96.1, 96.1), RH = c(29.7, 29.2, 35.1, 38.9, 44, 52.9, 55.1,
    57.8, 62.1, 68.1, 69.5, 68.3, 71.9, 76.4, 80.6, 80.4, 80.5,
    78.1, 66.8, 54, 45, 38.8, 34.7, 32.6, 30.2, 31.5, 33.8, 35.4,
    39.5, 46.9, 59.8, 72.9, 69.6, 81.7, 82.9, 81.7, 82.6, 83.1,
    84.5, 81.8, 81), cas = structure(list(sec = c(0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), min = c(0L,
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), hour = c(10L, 11L,
    12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L,
    0L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L,
    14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 0L, 1L,
    2L), mday = c(28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
    28L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
    29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L, 29L,
    29L, 29L, 29L, 29L, 29L, 30L, 30L, 30L), mon = c(2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), year = c(114L, 114L,
    114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L,
    114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L,
    114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L,
    114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L, 114L), wday = c(5L,
    5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L,
    6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L,
    6L, 6L, 6L, 6L, 6L, 6L, 6L, 0L, 0L, 0L), yday = c(86L, 86L,
    86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L, 86L,
    87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L,
    87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L,
    88L, 88L, 88L), isdst = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
    0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L,
    0L, 0L, -1L), zone = c("CET", "CET", "CET", "CET", "CET",
    "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET",
    "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET",
    "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET",
    "CET", "CET", "CET", "CET", "CET", "CET", "CET", "CET", ""
    ), gmtoff = c(NA_integer_, NA_integer_, NA_integer_, NA_integer_,
    NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
    NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
    NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
    NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
    NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
    NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
    NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_,
    NA_integer_, NA_integer_)), class = c("POSIXlt", "POSIXt"
    ))), row.names = c(NA, -41L), class = "data.frame")
>


> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of Emeka Don
> Sent: Monday, March 12, 2018 12:18 PM
> To: [hidden email]
> Subject: [R] Help on Aggregation
>
> Dear All,
> 1.I have been trying to aggregate my data but I have not been getting it
> correctly. In the data I want to convert hourly data into daily averages.
> Here is a sample of the data:
> Neph_no Date Time Temp_C   Pressure_kPa RH
> 9   2014/03/28  10:00:00 38.4 95.9 29.7
> 9   2014/03/28  11:00:00 37.8 95.8 29.2
> 9   2014/03/28  12:00:00 36.7 95.8 35.1
> 9   2014/03/28  13:00:00 35.4 95.8 38.9
> 9   2014/03/28  14:00:00 34.1 95.8 44
> 9   2014/03/28  15:00:00 32.7 95.9 52.9
> 9   2014/03/28  16:00:00 31.8 96 55.1
> 9   2014/03/28  17:00:00 31.2 96 57.8
> 9   2014/03/28  18:00:00 30.6 96.1 62.1
> 9   2014/03/28  19:00:00 29.8 96.1 68.1
> 9   2014/03/28  20:00:00 29.1 96.1 69.5
> 9   2014/03/28  21:00:00 28.6 96 68.3
> 9   2014/03/28  22:00:00 28 96 71.9
> 9   2014/03/28  23:00:00 27.4 95.9 76.4
> 9   2014/03/29  00:00:00 27 96 80.6
> 9   2014/03/29  01:00:00 27.1 96 80.4
> 9   2014/03/29  02:00:00 27 96.1 80.5
> 9   2014/03/29  03:00:00 27.8 96.1 78.1
> 9   2014/03/29  04:00:00 30.4 96.2 66.8
> 9   2014/03/29  05:00:00 33.7 96.3 54
> 9   2014/03/29  06:00:00 36.3 96.3 45
> 9   2014/03/29  07:00:00 37.7 96.3 38.8
> 9   2014/03/29  08:00:00 38.7 96.3 34.7
> 9   2014/03/29  09:00:00 38.9 96.1 32.6
> 9   2014/03/29  10:00:00 39.4 96 30.2
> 9   2014/03/29  11:00:00 38.9 95.9 31.5
> 9   2014/03/29  12:00:00 38.2 95.8 33.8
> 9   2014/03/29  13:00:00 37.4 95.8 35.4
> 9   2014/03/29  14:00:00 35.8 95.9 39.5
> 9   2014/03/29  15:00:00 33.9 96 46.9
> 9   2014/03/29  16:00:00 31.4 96.1 59.8
> 9   2014/03/29  17:00:00 29.4 96.3 72.9
> 9   2014/03/29  18:00:00 29 96.3 69.6
> 9   2014/03/29  19:00:00 26.5 96.2 81.7
> 9   2014/03/29  20:00:00 27 96.1 82.9
> 9   2014/03/29  21:00:00 27.5 96.1 81.7
> 9   2014/03/29  22:00:00 27.4 96 82.6
> 9   2014/03/29  23:00:00 27.3 96 83.1
> 9   2014/03/30  00:00:00 27.1 96 84.5
> 9   2014/03/30  01:00:00 27.6 96.1 81.8
> 9   2014/03/30  02:00:00 27.8 96.1 81
>
> 2. I have some data of about 6100 rows and 6 columns, but anytime i read it
> into R, it removes the header and a large chunk of the data.( i:e it will import
> from row 3550-6099). This is the code i used for it
> "met_data=read.csv(file.choose(),header=TRUE)", so, how do I read the entire
> data into R without missing some?
> Thank you.
>
> --
> Onyeuwaoma Nnaemeka Dom
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.
______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.