Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的子集在2个月内的一段时间内_R - Fatal编程技术网

R中的子集在2个月内的一段时间内

R中的子集在2个月内的一段时间内,r,R,我一直在使用下面的代码对数据进行子集划分 setwd("C:/Users/A/Desktop") vf <- read.csv("Height.csv", header = TRUE) #Insert month and Day(s) desired vf1 <- vf [ which(vf$Month==9 & vf$Day>0 & vf$Day <31), ] vf2 <- vf1[c(-1,-2,-3)] setwd(“C:/Users/A/

我一直在使用下面的代码对数据进行子集划分

setwd("C:/Users/A/Desktop")
vf <- read.csv("Height.csv", header = TRUE)
#Insert month and Day(s) desired
vf1 <- vf [ which(vf$Month==9 & vf$Day>0 & vf$Day <31), ]
vf2 <- vf1[c(-1,-2,-3)]
setwd(“C:/Users/A/Desktop”)

vf正如@JoshuaUlrich所说,一次观察的月份不能同时是两个值。 像这样的方法会奏效:

vf1 <- vf [ which( vf$Month==4 & vf$Day>19 | vf$Month ==5 & vf$Day <32 ), ]

vf1 19 | vf$Month==5&vf$Day
vfMonth
永远不可能同时是4和5,因此
vf$Month==4&vf$Month==5
永远不会是
TRUE
@JoshuaUlrich那么如何才能将其作为事实陈述呢<代码>月份==4和5
?对不起,这不是很有帮助。老实说。@ja thomas是的,这就是我想要做的,只是必须改变#32。你能解释一下为什么代码中必须有一个
|
?我还在学R。谢谢@LyzandeR你能解释一下你的意思吗?
vf1 <- vf [ which(vf$Month==4 & vf$Day>19 & vf$Day <31), which(vf$Month ==5 & vf$Day>19 & vf$Day <32), ]
Error in `[.data.frame`(vf, which(vf$Month == 4 & vf$Day > 19 & vf$Day <  : 
  undefined columns selected
vf1 <- vf [ which( vf$Month==4 & vf$Day>19 | vf$Month ==5 & vf$Day <32 ), ]