Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.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中编写一个for循环,如果满足条件,该循环将向向量添加值_R_For Loop_If Statement_Vector - Fatal编程技术网

尝试在R中编写一个for循环,如果满足条件,该循环将向向量添加值

尝试在R中编写一个for循环,如果满足条件,该循环将向向量添加值,r,for-loop,if-statement,vector,R,For Loop,If Statement,Vector,我试图定义一个名为IQR的向量,它返回另一个向量的内四分位数范围内的值(不是以数字顺序) 我已经尝试了多次迭代 IQR <- function(y) for (i in seq_along(y)) { if ((i > quantile(y, 0.25)) && (i < quantile(y, 0.75))) {iqr <- c(i)} else {break}} IQR分位数(y,0.25))&&(i

我试图定义一个名为IQR的向量,它返回另一个向量的内四分位数范围内的值(不是以数字顺序)

我已经尝试了多次迭代

IQR <- function(y) for (i in seq_along(y)) { if ((i > quantile(y, 0.25)) && (i < quantile(y, 0.75))) {iqr <- c(i)} else {break}}

IQR分位数(y,0.25))&&(i[]
选择满足条件的向量元素

大概是这样的:

IQR <- function(y)  y[ y>quantile(y,0.25) & y<quantile(y,0.75) ]  
# read as 'y, where y is greater than the 25th centile of y and y is less than the 75th centile of y'

IQR(1:10)
[1] 4 5 6 7


IQR分位数(y,0.25)&y请分享更多细节,如输出是什么
IQR <- function(y)  y[ y>quantile(y,0.25) & y<quantile(y,0.75) ]  
# read as 'y, where y is greater than the 25th centile of y and y is less than the 75th centile of y'

IQR(1:10)
[1] 4 5 6 7