Return a dataframe from a function and store it in the workspace

Viewed 13052

This is my first week working with R and there is one thing about function I cannot seems to manage.

df <- data.frame(a = c(1:10),
             b = c("a", "a", "b", "c", "c", "b", "a", "c", "c", "b"))

testF = function(select) {
dum = subset(df, b == select)
}

lapply(unique(df$b), testF)

This function now just prints the the data sets on screen. But I would like to store the results as separate data frames in my workspace. In this example this would give three data frames; a, b and c.

Thank for the help.

3 Answers
Related