I have only just started using R and coming from programming in Python, I really like making functions. I want to apply the count method on a dataframe and assign the column name ('col_name') with the argument that is given to the function. My end goal is to loop through the column names (col_names <- colnames(df))) and apply the function to each column individually and to create a new dataframe based on these counts.
However, it always gives me an error that the column name is not found in the data frame ( Error: Must group by variables found in .data. Column col_name is not found*). I also tried to to apply rlang::sym to the argument and also tried it with the prefix !!. While this option at least didn't give me an error, it didn't select the column and returned a dataframe with the number of rows in the column col_name.
Does anyone know how to help?
I'd also appreciate any suggestions how to achieve my goal in a more efficient way.
Thanks and best,
Eva
Hi @HanOostdijk
Great, thanks a lot.
Actually the sum_method still gives me this error:
Error: Problem with summarise() column x. x = sum(pos_word_stem).
x invalid 'type' (character) of argument
But the count_method (which is what I need) works perfectly.