R中两个数据帧之间的条件和

时间:2016-04-19 15:45:34

标签: r

我有一个包含日期和更多信息的数据框。我想创建一个只有两列的新数据框:唯一的日期和它们出现在" main"中的次数。数据帧。我已经四处搜索但无法找到任何内容,我发现的所有示例都限于使用来自同一数据帧的数据。

2 个答案:

答案 0 :(得分:1)

对于具有日期变量日期的数据帧df,请尝试

newdf <- as.data.frame(table(df$dates))
names(newdf) <- c("dates", "counts")

答案 1 :(得分:1)

试试这个:

#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
相关问题