Hi,
I would like to extract monthly data automatically using a code. Given are my
sample data.
I know how to do one by one:
jan_data1 <- Pooraka_data[Pooraka_data$Month=="1",4]
feb_data1 <- Pooraka_data[Pooraka_data$Month=="2",4]
mar_data1 <- Pooraka_data[Pooraka_data$Month=="3",4]
apr_data1 <- Pooraka_data[Pooraka_data$Month=="4",4]
...
then i try:
p0_mn <- function(dt)
{ p0 <- sum(dt==0)/length(dt)
mn <- mean(dt)
c(p0=p0, mn=mn)
}
rbind(p0_mn(jan_data2),p0_mn(feb_data1),
p0_mn(mar_data1),p0_mn(apr_data1),p0_mn(may_data1),p0_mn(jun_data1),p0_mn(jul_data1),
p0_mn(aug_data1),p0_mn(sep_data1),p0_mn(oct_data1),p0_mn(nov_data1),p0_mn(dec_data1))
)
> head(Pooraka_data,20); tail(Pooraka_data,20)
Year Month Day Amount
1 1901 1 1 0.0
2 1901 1 2 3.0
3 1901 1 3 0.0
4 1901 1 4 0.5
5 1901 1 5 0.0
6 1901 1 6 0.0
7 1901 1 7 0.3
8 1901 1 8 0.0
9 1901 1 9 0.0
10 1901 1 10 0.0
11 1901 1 11 0.5
12 1901 1 12 1.8
13 1901 1 13 0.0
14 1901 1 14 0.0
15 1901 1 15 2.5
16 1901 1 16 0.0
17 1901 1 17 0.0
18 1901 1 18 0.0
19 1901 1 19 0.0
20 1901 1 20 0.0
Year Month Day Amount
32858 1990 12 17 0.0
32859 1990 12 18 0.0
32860 1990 12 19 0.8
32861 1990 12 20 0.0
32862 1990 12 21 0.0
32863 1990 12 22 8.0
32864 1990 12 23 0.0
32865 1990 12 24 0.0
32866 1990 12 25 0.0
32867 1990 12 26 0.0
32868 1990 12 27 0.4
32869 1990 12 28 0.0
32870 1990 12 29 0.0
32871 1990 12 30 0.0
32872 1990 12 31 0.0
32873 1991 1 1 0.0
32874 1991 1 2 0.0
32875 1991 1 3 0.0
32876 1991 1 4 0.0
32877 1991 1 5 5.4
thank you.
[[alternative HTML version deleted]]