I am trying to create a function for a series of rounding work in R, I have percentage, decimals, etc, each of them need to be rounded differently.
I start writing the function by first picking up the object I want, but I fail to do that already, here’s the code:
roundings <- function(obj.head)
{obj.list <- ls(pattern=obj.head)
obj.list
}
Suppose I have two object A1 and B1, I suppose if I run roundings("A"), A1 should appear as the function output, but it didn’t.
What have I done wrong? Thanks.
The call to
lsis searching the current environment within the function and does not find any objects to match. You can specify theenvirparameter inlswith.GlobalEnv. Thus your code becomes: