mardi 7 juillet 2015

Multiple If Statements in R

I've been trying to figure this out all day but to no avail. I have an if statement that is meant to satisfy four possible conditions.

  1. A exists and B does not exist
  2. B exists and A doesn't exist
  3. A & B exist
  4. A & B do not exist

A, B, C are dataframes.

Here is my code:

if (!exists("A") & exists("B")) {
  C= B} 
else if (exists("A") & !exists("B")) {
  C= A}
else if (exists("A") & exists("B")) {
  C= rbind(B,A)} 
else {C <- NULL}

I keep getting an error on unexpected "}" and unexpected "else". I've followed several examples but still facing this challenge. Any pointers would be much appreciated. Thx.

Aucun commentaire:

Enregistrer un commentaire