The crux of your problem isn't making that object not be a string, it's convincing R to do what you want with the string. You can do this with, e.g., eval(parse(text = foo)). Isolating out a small working example:
y <- "iris$Sepal.Length"
data.frame(as.list(y))                      # does not display iris$Sepal.Length
data.frame(as.list(eval(parse(text = y))))  # DOES display iris.$Sepal.Length
That said, I wanted to point out some issues with your function:
- The input variable appears to not do anything (because it is immediately overwritten), which may not have been intended.
- The forloop seems broken, since it resetscountto 1 on each pass, which I think you didn't mean. Relatedly, it iterates over alli in iris, but then it doesn't useiin any meaningful way other than to keep a count. Instead, you could do something likefor(count in 1 : length(iris)which would establish thecountvariable and iterate it for you as well.
- It's generally better to avoid forloops in R entirely; there's a host of families available for doing functions to (e.g.) every column of a data frame. As a very simple version of this, something likeapply(iris, 2, table)will apply thetablefunction along margin 2 (the columns) ofirisand, in this case, place the results in a list. The idea would be to build your function to do what you want to a single vector, then pass each vector through the function with something from theapply()family. For instance:
cleantable <- function(x) {
  myspan = seq(min(x), max(x))  # if unspecified, by = 1
  myfreq = cut(x, breaks = myspan, right = FALSE)
  table(myfreq)
}
apply(iris[1:4], 2, cleantable)  # can only use first 4 columns since 5th isn't numeric
would do what I think you were trying to do on the first 4 columns of iris. This way of programming will be generally more readable and less prone to mistakes.