如何使用R显示日期范围
我对使用如何使用R显示日期范围,r,r-markdown,R,R Markdown,我对使用R非常陌生。我试图用数据集做一些基本的工作。我的数据集只有一列(date),其中包含参与者在调查中填写的日期: 11/11/2015 11/11/2015 11/11/2015 11/11/2015 11/11/2015 11/11/2015 11/11/2015 11/11/2015 27/11/2015 27/11/2015 etc (there are about 180 more responses) 到目前为止,我已经做了: NUdates <- nrow(unique
R
非常陌生。我试图用数据集做一些基本的工作。我的数据集只有一列(date
),其中包含参与者在调查中填写的日期:
11/11/2015
11/11/2015
11/11/2015
11/11/2015
11/11/2015
11/11/2015
11/11/2015
11/11/2015
27/11/2015
27/11/2015
etc (there are about 180 more responses)
到目前为止,我已经做了:
NUdates <- nrow(unique(date))
然后使用降价,我可以说:
参与者在r(月)
和r(月)
的r(年)
之间的r(月)
天内完成调查
要移除无关材料,您可以使用取消分类
:
dput(max(dates) - min(dates))
structure(0, units = "days", class = "difftime")
unclass(max(dates) - min(dates))
[1] 16
attr(,"units")
[1] "days"
这个答案是假设您在序列中找到了您的唯一日期。 下一步-
1) 确保你的日期按顺序排列。你可以这样做-
table <- table[order(table$Date),]
表我怀疑?range
功能是否会在这里切断它。您是否尝试过?min
或?max
?Noperange
函数不起作用,至少不适用于日期所采用的格式,也不会min
max
,原因相同:FUN中的错误(X[[i]],…):仅在数据框上定义,且所有数字变量都用as.date包装。听着,我可以帮你解决你的问题,但你需要给我们提供一个可复制的例子。我们没有时间猜测您的数据并手动创建变量。因此,在问问题之前,请先阅读规则。函数名为as.Date
感谢您的帮助,这正是我所需要的。我曾尝试使用as.Date函数,但未正确指定格式。非常感谢。
> max(dates) - min(dates)
Time difference of 16 days
dput(max(dates) - min(dates))
structure(0, units = "days", class = "difftime")
unclass(max(dates) - min(dates))
[1] 16
attr(,"units")
[1] "days"
table <- table[order(table$Date),]
start_date <- timeFirstDayInMonth(table$Date[1]) #First Date Of First Occuring Month
end_date <- timeLastDayInMonth(table$Date[nrow(table)-1]) #Last Date Of Last Occuring Month
Emonth <- format(start_date, format = "%B") #Full Month name
Lmonth <- format(end_date, format = "%m") #Decimal Month