I have a data frame with dates and more information. I want to create a new data frame with just two columns: the unique dates and the amount of times they appear in the "main" dataframe. I've searched around but can't find anything, all the examples I find are limited to using data from the same dataframe.
Asked
Active
Viewed 165 times
2 Answers
1
for dataframe df with date variable dates try
newdf <- as.data.frame(table(df$dates))
names(newdf) <- c("dates", "counts")

lmo
- 37,904
- 9
- 56
- 69
-
1Thanks for the catch @Frank. – lmo Apr 19 '16 at 18:22
1
Try this:
#creates a test df
employee <- c('A','B','C')
startdate <- as.Date(c('2010-11-1','2008-3-25','2008-3-25'))
employDF <- data.frame(employee, startdate)
# creates new df base on startdate column and count freq
testDF <- data.frame(table(employDF$startdate))
# changes the column names
names(testDF) <- c("startdate", "counts")
# prints out
testDF

NangSaigon
- 1,253
- 12
- 14
-
-
see the edits, time of update, you will see which one provide the correct one first – NangSaigon Apr 20 '16 at 02:12