vendredi 4 juin 2021

How do I create NaN's if sum equals 0 using ifelse... but within another ifelse where the else creates a variable?

How do I add a conditional (ifelse) where: if (sum of two vectors) equals 0, then create NaN, else go ahead and use those non-zero-values to create vector #3 (which is a function)?

Thank you!

Example:

# who let the dogs out?
dogsA <- fido + fifi 
dogsB <- sadie + jessica 

# who let the cats out?
catsA <- meowy + tinker
catsB <- pussyshnooks + catella

dog_gone_it <-c(sum(dogsA),sum(dogsB))
cat_chya_later <-c(sum(catsA),sum(catsB))

#insert ifelse here (like so?)
ifelse(c(dog_gone_it + cat_chya_later), 0, NaN) 

# But, if the above `ifelse` is not all 0's then i want the 
# code to create a particular vector using a particular function

animal_shelter <- some_function(dog_gone_it, cat_chya_later, code_magic)```

Aucun commentaire:

Enregistrer un commentaire