Last active
December 24, 2017 03:05
-
-
Save ClintWeathers/0d7496cf1c42df5ad4e6 to your computer and use it in GitHub Desktop.
Trying to make a new dataframe using Dplyr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Trying to create new dataframes from dplyr 0.4.3 functions using R 3.2.2. | |
#Very Simple Example: | |
paste("cars_with", 6, "cylinders", sep = "_") <- filter(mtcars, cyl == 6) | |
#What I want there is a dataframe named "cars_with_6_cylinders" that has the results of this: | |
filter(mtcars, cyl == 6) | |
#But instead, what I get is this: | |
"Error in paste("cars_with", 6, "cylinders", sep = " ") <- filter(mtcars, : | |
target of assignment expands to non-language object" | |
#Ultimately, what I'd like is something more complex like: | |
paste("cars_with", 6, "cylinders", sep = "_") <- filter(mtcars, cyl == 6) %>% | |
group_by(gear) %>% | |
summarise(number_of_cars = n())) | |
#And wrap that up in a function like this: | |
gearframes <- function(x){ | |
paste("cars_with", x, "cylinders", sep = "_") <- filter(mtcars, cyl == x) %>% | |
group_by(gear) %>% | |
summarise(number_of_cars = n())) | |
} | |
#Then I could feed the function something like: | |
sapply(mtcars$cyl, gearframes) | |
#And get dataframes for each numer of cylinders in mtcars$cyl. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Did you ever figure this out? I am getting the same error when I resample my data with group_by() %>% sample_n() %>% bind_rows.