如何在R中按日期子集 [英] How to subset by date in R

查看:62
本文介绍了如何在R中按日期子集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试按日期进行子集化,并且能够使用此处找到的一些代码,但是新数据集包含原始数据集中的所有数据,而不是仅包含6/4/18日期的数据.

I am trying to subset by date and I am able to use some code found here but the new data set contains all of the data in the original data set NOT data with the date of 6/4/18 only.

我的数据集名称为Full,列标题为Date.

My data set name is Full and my column heading is Date.

下面是代码:

Full$date <- as.Date(Full$Date, format= "%m/%d/%Y")
Firstday <- subset(Full, Date = "6/4/18" & date < "6/5/18")

以下是数据示例

Date    Weight    Length  Metabolic rate ext.
6/4/18     45        150      8
6/4/18     35        145      9
6/8/18     15        125      10 
6/8/18     16        100      2

推荐答案

如果只想选择"6/4/18",则可以使用以下方法将其过滤掉:

If you want to select only "6/4/18" you could filter it out using:

library(dplyr)
Firstday <- Full %>% filter(Date == "6/4/18")

这篇关于如何在R中按日期子集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆