Mi código me devuelve "NULL" y se supone que el código está bien

edad<-function(x){
if(x!=10)
{return(x+1)}
else
{return(x+2)}
}
#Prueba la función con x=10
print(edad(10))

Debería devolverme 12 pero me devuelve "NULL" y no sé qué hacer, ¿alguna idea?

I am not sure what is wrong but you may have to assign (X +1} to a valiable.

I think this does what you want:

x <- 10

edad<-function(x){
y <- if(x == 10) x + 1 else x +2
return(y)
} 

edad(x)

Muchísimas gracias, ahora sí me va bien.

Su función original debería funcionar también, así que puede ser que funcione ahora si funciona la que sugerió @ jrkrideau

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.