mardi 3 mars 2020

Trying to write a for loop in R that adds values to a vector if a condition is satisfied

I was trying to define a vector called IQR that returns the values within the Inner quartile range of another vector(not in numerical order).

I have tried numerous iterations of

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}}

and

IQR <- vector('double', 0) for (i in seq_along(Vect)) {if ((i > quantile(y, 0.25)) && (i < quantile(y, 0.75))) {iqr <- vector(i)} else {break}}

where vect is a stand alone vector containing the values to test created from the df

Aucun commentaire:

Enregistrer un commentaire