0

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.

Hugo Torres
  • 308
  • 4
  • 13

2 Answers2

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
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