I wrote a function in R that returns a list composed of two variables. The function works correctly in that the correct values are returned. The problem, however, is that I can't then access the list for further processing. The code is this:
grinder <- function(x) {
if(x == "BID") {
miles <- 18.4 * n.row
tolls <- 1.8 * n.row
} else if(x == "SPR") {
miles <- 10.8 * n.row
tolls <- 0
} else if (x == "BRI") {
miles <- 3.8 * n.row
tolls <- 0
} else if (x == "GOO") {
miles <- 66.2 * n.row
tolls <- 1.8 * n.row
} else if (x == "MIL") {
miles <- 108
tolls <- 0
} else if (x == "SMH") {
miles <- 94.6 * n.row
tolls <- 2 * n.row
}
mil.tol <- list(miles,tolls)
return(mil.tol)
}
grinder(x)
The correct values are returned, but I can't then access mil.tol to do anything with those values. Nor can I get correct values for miles or tolls. The console returns this:
> mil.tol
Error: object 'mil.tol' not found
> miles
Any suggestions?