I am having trouble with a function I am trying to create. I want to convert numbers into assigned days of the week. For example: 1='Monday', 2='Tuesday', 3='Wednesday', 4='Thursday', 5='Friday', 6='Saturday', 0='Sunday'
Below is my attempt a writing the function, but I get an error, and I also think there must be a way to loop it. I just don't know how.
#experiment
pow <- function(x) {
if (x == 1)
{
print("Monday")
}
else if (x == 2)
{
print("Tuesday")
}
else if (x == 3)
{
print("Wednesday")
}
else if (x == 4)
{
print("Thursday")
}
else if (x == 5)
{
print("Friday")
}
else if (x == 6)
{
print("Saturday")
}
else if (x == 0)
{
print("Sunday")
}
else if (is.na(x) ==TRUE)
{print("Sorry, please enter two numbers.")
}
}