楼主: ariel1117
2078 4

[问答] R语言 如何按日期筛选数据后运行计算 [推广有奖]

  • 0关注
  • 0粉丝

等待验证会员

小学生

0%

还不是VIP/贵宾

-

威望
0
论坛币
10 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
46 点
帖子
3
精华
0
在线时间
4 小时
注册时间
2019-9-26
最后登录
2019-10-9

楼主
ariel1117 发表于 2019-9-26 13:40:08 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
申请日期批准日期补助总额补助1补助2其他补助
2019/1/22019/1/3101.001.008.00
2019/1/32019/1/2202.002.0016.00
2019/1/22019/1/3303.003.0024.00
2019/1/52019/1/1404.004.0032.00
2018/12/312019/1/2505.005.0040.00
2019/1/62019/1/1606.006.0048.00
2019/1/22019/1/4707.007.0056.00
2019/1/22019/1/2808.008.0064.00
2019/1/72019/1/2909.009.0072.00
2018/12/292019/1/210010.0010.0080.00


如图,我要计算:在申请日期批准日期2019/1/2的条件下,(补助1+补助2)/(补助总额)的值。

后半截的计算公式已经研究出来了,请问应该如何添加“在申请日期或批准日期为2019/1/2"这一条件?

数据有上万条,这是本人自学R的第二天,怎么弄都不对,望大神指导!~


二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝


647e3931fe6423deac2924f60234339.png (17.1 KB)

647e3931fe6423deac2924f60234339.png

沙发
jiangbeilu 学生认证  发表于 2019-9-27 07:31:21
给你一个例子,
subset(data,x1==4 | x2 ==6)

data是数据集,x1和x2是里面的变量。上述代码表示筛选x1为4或者x2为6的记录。

当然用dplyr包里的filter也是一样的过滤。

藤椅
hifinecon 发表于 2019-9-27 10:21:09
first of all, you have to be sure the date format is correct. you could use as.date to convert your data into date which R can recognize it. then use filter like this  filter(application_date >= as.Date("2019/1/2")  || approval_date <= as.Date("2019/1/2")), something like that, I am not sure about the OR sign, you should check it. cheers!

板凳
ariel1117 发表于 2019-9-27 14:59:02
jiangbeilu 发表于 2019-9-27 07:31
给你一个例子,
subset(data,x1==4 | x2 ==6)
谢谢!!
我笨拙地用subset解决了,接下来研究dplyr

报纸
ariel1117 发表于 2019-9-27 15:04:17
hifinecon 发表于 2019-9-27 10:21
first of all, you have to be sure the date format is correct. you could use as.date to convert your  ...
谢谢您,又学到了一招,我试试看

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-8 04:43