Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/67.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 如何在首次观测和最大值观测之间找到观测次数_R - Fatal编程技术网

R 如何在首次观测和最大值观测之间找到观测次数

R 如何在首次观测和最大值观测之间找到观测次数,r,R,我有一个大的数据框,我需要一个功能来自动搜索。基本上我想知道在第一次观测和最大值观测之间有多少观测 例如: x我们可以 diff(which(x %in% c(2, max(x)))) -1 #[1] 6 或者从第一个值中减去最大值(which.max)的索引(+1-不包括元素) 我需要自动化这个。如果我使用diff(其中x%在%c(2,max(x)))错误:意外符号在:“diff(其中x%在%c(2,max(x)))diff”@TigranDanielyan你能再试一次吗?因为我不能重新判断

我有一个大的数据框,我需要一个功能来自动搜索。基本上我想知道在第一次观测和最大值观测之间有多少观测

例如:

x我们可以

diff(which(x %in% c(2, max(x)))) -1
#[1] 6
或者从第一个值中减去最大值(
which.max
)的索引(+1-不包括元素)


我需要自动化这个。如果我使用
diff(其中x%在%c(2,max(x)))
错误:意外符号在:“diff(其中x%在%c(2,max(x)))diff”@TigranDanielyan你能再试一次吗?因为我不能重新判断这个错误我使用了
which.max(n)-n[1]-1
,谢谢!@TigranDanielyan我在想差异是来自max和1,而不是第一个值
which.max(x) - x[1]