Skip to content
Prev 324922 / 398503 Next

Get count by day for particular coulmn

Hi,
On Fri, Jun 7, 2013 at 7:38 AM, R_Antony <antony.akkara at ge.com> wrote:
Since you didn't provide reproducible data (dput() is great for that),
here's an example with fake data:


MyDF <- data.frame(DATETIME = c("1/1/2007", "1/1/2007", "1/1/2007",
"1/2/2007", "1/2/2007", "1/2/2007", "1/3/2007", "1/3/2007",
"1/3/2007"),
COL_A = c(0, 0, 0, 1, 0, 1, 2, 3, 1),
COL_B = c(0, 3, 0, 3, 3, 1, 0, 1, 2),
COL_C = c(1, 2, 3, 1, 2, 3, 1, 2, 3), stringsAsFactors=FALSE)

aggregate(COL_B ~ DATETIME, data=MyDF, FUN=function(x)sum(x == 3))
You omitted a comma:
MyDF[MyDF["DATETIME"]=="1/2/2007", ]


You might prefer:
subset(MyDF, DATETIME == "1/2/2007")

Sarah