lundi 26 décembre 2016

How to save the outcomes of a Loop (with if statement) in R?

Is it possible to save the outcome of a loop in a vector? My goal is to have a vector (or list) with the dates (of the vector"gifts") that are smaller than one specific date (date_3 in the code).

for (i in 1:21) {
if ((!is.na(gifts[i])) & (gifts[i] < Date_3)) {
  print(gifts[i])
}
}

"Gifts" represents a vector that contains a number of dates. Date_3 is a specific date

Can anyone help? Thanks

Aucun commentaire:

Enregistrer un commentaire