【发布时间】:2014-07-12 15:26:29
【问题描述】:
我目前有一个列“月”和一个列“DayWeek”,其中列出了一周中的月份和日期。使用下面的代码,我可以在 2 月、5 月、8 月和 11 月的每个星期三得到一个 1 的列。我正在努力寻找一种方法,在我刚刚提到的 4 个月中的每个月的第一个星期三得到一个 1 的列.有什么想法还是我必须为它创建一个循环?
testPrices$Rebalance <- ifelse((testPrices$Month=="February" & testPrices$DayWeek == "Wednesday"),1,ifelse((testPrices$Month=="May" & testPrices$DayWeek == "Wednesday"),1,ifelse((testPrices$Month=="August" & testPrices$DayWeek == "Wednesday"),1,ifelse((testPrices$Month=="November" & testPrices$DayWeek == "Wednesday"),1,0))))
【问题讨论】:
标签: r date if-statement