On Aug 7, 2009, at 3:36 PM, Felipe Carrillo wrote:
> Hi all:
> I am trying to use the ddply function to estimate the mean of
> 'Total','Fry','Smolt' and 'Fry.Eq' columns
without success. I have
> the dput of my dataset below. I wonder if someone can give me a hand
> with this function.
>
> # dput(winter)
> winter <-structure(list(IDDate = structure(c(37L, 48L, 59L, 62L, 63L,
> 64L, 65L, 66L, 67L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L,
> 47L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 60L, 61L,
> 68L, 79L, 90L, 93L, 94L, 95L, 96L, 97L, 98L, 69L, 70L, 71L, 72L,
> 73L, 74L, 75L, 76L, 77L, 78L, 80L, 81L, 82L, 83L, 84L, 85L, 86L,
> 87L, 88L, 89L, 91L, 92L, 99L, 110L, 121L, 123L, 124L, 125L, 126L,
> 127L, 128L, 100L, 101L, 102L, 103L, 104L, 105L, 106L, 107L, 108L,
> 109L, 111L, 112L, 113L, 114L, 115L, 116L, 117L, 118L, 119L, 120L,
> 122L, 2L, 13L, 24L, 27L, 28L, 29L, 30L, 31L, 32L, 3L, 4L, 5L,
> 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L, 15L, 16L, 17L, 18L, 19L,
> 20L, 21L, 22L, 23L, 25L, 26L, 33L, 34L, 35L, 36L), .Label = c("",
> "10/1/2008", "10/10/2008", "10/11/2008",
"10/12/2008", "10/13/2008",
> "10/14/2008", "10/15/2008", "10/16/2008",
"10/17/2008", "10/18/2008",
> "10/19/2008", "10/2/2008", "10/20/2008",
"10/21/2008", "10/22/2008",
> "10/23/2008", "10/24/2008", "10/25/2008",
"10/26/2008", "10/27/2008",
> "10/28/2008", "10/29/2008", "10/3/2008",
"10/30/2008", "10/31/2008",
> "10/4/2008", "10/5/2008", "10/6/2008",
"10/7/2008", "10/8/2008",
> "10/9/2008", "11/1/2008", "11/2/2008",
"11/3/2008", "11/4/2008",
> "7/1/2008", "7/10/2008", "7/11/2008",
"7/12/2008", "7/13/2008",
> "7/14/2008", "7/15/2008", "7/16/2008",
"7/17/2008", "7/18/2008",
> "7/19/2008", "7/2/2008", "7/20/2008",
"7/21/2008", "7/22/2008",
> "7/23/2008", "7/24/2008", "7/25/2008",
"7/26/2008", "7/27/2008",
> "7/28/2008", "7/29/2008", "7/3/2008",
"7/30/2008", "7/31/2008",
> "7/4/2008", "7/5/2008", "7/6/2008",
"7/7/2008", "7/8/2008",
> "7/9/2008",
> "8/1/2008", "8/10/2008", "8/11/2008",
"8/12/2008", "8/13/2008",
> "8/14/2008", "8/15/2008", "8/16/2008",
"8/17/2008", "8/18/2008",
> "8/19/2008", "8/2/2008", "8/20/2008",
"8/21/2008", "8/22/2008",
> "8/23/2008", "8/24/2008", "8/25/2008",
"8/26/2008", "8/27/2008",
> "8/28/2008", "8/29/2008", "8/3/2008",
"8/30/2008", "8/31/2008",
> "8/4/2008", "8/5/2008", "8/6/2008",
"8/7/2008", "8/8/2008",
> "8/9/2008",
> "9/1/2008", "9/10/2008", "9/11/2008",
"9/12/2008", "9/13/2008",
> "9/14/2008", "9/15/2008", "9/16/2008",
"9/17/2008", "9/18/2008",
> "9/19/2008", "9/2/2008", "9/20/2008",
"9/21/2008", "9/22/2008",
> "9/23/2008", "9/24/2008", "9/25/2008",
"9/26/2008", "9/27/2008",
> "9/28/2008", "9/29/2008", "9/3/2008",
"9/30/2008", "9/4/2008",
> "9/5/2008", "9/6/2008", "9/7/2008",
"9/8/2008", "9/9/2008"), class =
> "factor"),
> Total = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 77, 0,
> 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402, 170, 322,
> 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792, 1998.32,
> 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11, 5540, 11515,
> 11703, 21135, 18770, 16686, NA, NA, NA, NA, 28385, 57310,
> 53024, NA, NA, NA, NA, 34787, 28768, 25947, 23761, 18430,
> 13080, 14094, 13638, 14748, 11564, 8076, 15123, 14192, 13648,
> 14393, 19338, 25597, 26892, 28353, 18197, 18060, 11143, 13912,
> 9915, 12240, 20541, 6643, 7408, 5511, 10797, 10706, 9654,
> 6968, 4896, 4659, 5180, 4234.42, 5626, 3678, 2504, 1299,
> 957.07, 2296, 2318, 1942.19, 2703.78, 5183, 4286, 3201, 2617,
> 2118, 1633, 1740, 1791, 1023, 391, 884.97, 1214.5, 7927,
> 8462), Fry = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402,
> 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792,
> 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11,
> 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA,
> 28385, 57090, 53024, NA, NA, NA, NA, 34405, 28563, 25947,
> 23664, 18391, 13009, 13992, 13442, 14678, 11564, 8012, 15123,
> 13990.16, 13372.5, 14205, 18687, 25003.66, 25927, 27596,
> 17755, 17438, 10630.83, 12879, 9389, 11882, 19368, 5936,
> 6182, 4462, 7606, 7933.89, 7010, 5052, 3199, 2894, 2395,
> 1253, 1994, 1180.62, 1024, 520, 410, 923, 547, 448, 674,
> 902, 1085, 559, 694, 200, 40, 41, 162.43, 0, 0, 88.09, 0,
> 79, 243), Smolt = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 0, 0, 0, 0, NA, NA, NA, 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, NA, NA, NA, NA, 0, 220, 0, NA, NA, NA,
> NA, 382, 204.45, 0, 98, 39, 70.74, 102.45, 196, 70, 0, 64,
> 0, 201.6, 276, 188, 650, 594, 965, 757, 442, 622, 512, 1033,
> 526, 357, 1173, 707, 1226, 1049, 3192, 2772, 2644, 1916.03,
> 1697.59, 1765.08, 2785.12, 2981, 3632, 2497, 1480, 778.94,
> 547.27, 1373, 1771, 1495, 2030, 4281, 3200, 2642.26, 1922.53,
> 1918, 1593, 1699, 1628, 1023, 391, 796.88, 1214.5, 7847,
> 8219), Fry.Eq = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
> 0, 77, 0, 0, 0, NA, NA, NA, 70, 0, 0, 55, 0, 52, 52, 0, 402,
> 170, 322, 635, 197, 444, 206, 0, 210, 598, 2406, 2476, 1792,
> 1998.32, 2235, 3184, 2897, 3325.59, 908.77, 2125, 2638.11,
> 5540, 11515, 11703, 21135, 18770, 16686, NA, NA, NA, NA,
> 28385, 57464, 53024, NA, NA, NA, NA, 35055, 28911, 25947,
> 23830, 18457.87, 13129, 14166, 13775.76, 14797, 11564, 8121,
> 15123, 14333, 13841, 14524, 19793, 26013, 27567, 28883, 18506.87,
> 18494.87, 11502, 14635, 10283, 12490, 21362, 7138, 8267,
> 6245, 13032, 12646.37, 11505, 8309, 6085, 5894.51, 7129.24,
> 6321, 8168, 5425, 3540.31, 1844.04, 1340, 3257, 3557, 2988,
> 4125, 8180, 6526, 5051, 3962, 3461, 2748, 2929, 2931, 1739,
> 665, 1443, 2065, 13420, 14216), IDWeek = c(27L, 27L, 27L,
> 27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L, 28L, 28L, 28L,
> 29L, 29L, 29L, 29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 30L,
> 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 32L, 32L, 32L,
> 32L, 32L, 32L, 32L, 33L, 33L, 33L, 33L, 33L, 33L, 33L, 34L,
> 34L, 34L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L, 35L, 35L,
> 35L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 37L, 37L, 37L, 37L,
> 37L, 37L, 37L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 39L, 39L,
> 39L, 39L, 39L, 39L, 39L, 40L, 40L, 40L, 40L, 40L, 40L, 40L,
> 41L, 41L, 41L, 41L, 41L, 41L, 41L, 42L, 42L, 42L, 42L, 42L,
> 42L, 42L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 44L, 44L, 44L,
> 44L, 44L, 44L, 44L), ID.Month = c(7L, 7L, 7L, 7L, 7L, 7L,
> 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
> 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L,
> 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L,
> 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 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, 10L, 10L, 10L,
> 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
> 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L,
> 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L)), .Names = c("IDDate",
> "Total", "Fry", "Smolt", "Fry.Eq",
"IDWeek", "ID.Month"), row.names
> = c(NA,
> 127L), class = "data.frame")
>
> attach(winter)
> str(winter)
> # dummy code
> i <-
> ddply
> (winter
> ,c
> ("IDWeek
>
"),transform,weeklymean=c(mean('Total','Fry','Smolt','Fry.Eq')))
> i
Instead perhaps:
> ddply(winter[, -c(1,7)],.(IDWeek),mean, na.rm=TRUE)
Total Fry Smolt Fry.Eq IDWeek
1 0.00000 0.00000 0.00000 0.00000 27
2 11.00000 11.00000 0.00000 11.00000 28
3 17.50000 17.50000 0.00000 17.50000 29
4 22.71429 22.71429 0.00000 22.71429 30
5 339.42857 339.42857 0.00000 339.42857 31
6 1354.33143 1354.33143 0.00000 1354.33143 32
7 2473.35286 2473.35286 0.00000 2473.35286 33
8 14224.83333 14224.83333 0.00000 14224.83333 34
9 46239.66667 46166.33333 73.33333 46291.00000 35
10 28315.75000 28144.75000 171.11250 28435.75000 36
11 13375.71429 13298.28571 77.45571 13430.09000 37
12 18454.71429 18044.04571 410.65714 18742.00000 38
13 15974.28571 15367.11857 607.00000 16399.24857 39
14 10180.00000 8356.84143 1823.28571 11456.48143 40
15 5034.48857 2566.80286 2467.68857 6761.67857 41
16 2002.86286 649.42857 1353.60143 2950.19286 42
17 2968.28571 503.00000 2465.11286 4693.85714 43
18 3099.06714 81.78857 3017.05429 5211.28571 44
--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT