I got error for apply count_ to all my dataframes. I can manually apply to single dataframe, but when I tried lapply
, it showed error
Error in UseMethod("groups") : no applicable method for 'groups' applied to an object of class "character"
I want to find the unique pairs of longitude and latitute in my dataset. For single dataframe I used dplyr::count_(d, vars = c('longitude','latitute '))
, which return a table of pairs of values and the count number. I want to check the unique pairs in each of dataframe and store them in separate files. Currently I tried put all my dataframes in a list and used for
loop.
For single data frame, I used
dplyr::count_(CA, vars = c('locationlongitude','locationlatitude'))
###it returns output like this
locationlongitude locationlatitude n
<dbl> <dbl> <int>
1 -72.0 42.6 47
2 -72.0 42.6 69
3 -71.8 42.6 59
4 -71.7 42.5 93
5 -71.7 42.5 65
Then I want to apply to all my data frames
for (i in files) {
nam <- paste("B_", i)
assign(nam, dplyr::count_(i, vars = c('locationlongitude', 'locationlatitude')))
}
files
is a list of all my dataframes' name and I expected created dataframes begin with B_+dataframesname to store my unique locations from each data frame. But there is
Error in UseMethod("groups") : no applicable method for 'groups' applied to an object of class "character".
I also tried to create files as a list and each elements will be the dataframe but I got another error when doing that:
Error in assign(nam, dplyr::count_(i, vars = c("locationlongitude", "locationlatitude"))) : variable names are limited to 10000 bytes In addition: Warning message: In assign(nam, dplyr::count_(i, vars = c("locationlongitude", "locationlatitude"))) : only the first element is used as variable name
I believe there should be a efficient way to apply function to multiple data frame and return another data frame. But I'm stuck. I'd appreciated any comments!