Error in mutate_impl(.data, dots) :
Column `.` must be length 32 (the number of rows) or one, not 2
It is working on a columns level here i.e. disp and draft where mutate is expecting something of an exact length of the original dataframe in terms of number of rows (i.e. 32) instead of the 2 it is receiving. I hope this helps?
@leoncio you can use the below syntax for this. Different variants of mutate, e.g. mutate_at, mutate_if, mutate_all, mutate_each all are intended to accomplish this task. Alternatively, if you have an updated version of dplyr, I believe the function across can also work here.
Yes, I just wondered why mutate command does not work when the above does.
the {} instead of mutate are new to me. Thought the mutate command has some minor mistake and after correction would work the same..
Not a bug, you are merely using the wrong syntax, you have to use the across() function inside mutate() if you want to work "across" variables (Or use the old syntax described in the previous comment).
Could you refer me to some explanation as to using ~ and . instead of repeating arguments/ writing function(x)..
I somehow do not see this in entry courses in R and their usage eludes me..
e.g. in the example above, what ~ and . stand for, and could they be exchanged into some more "traditional" arguments/functions and work the same?
~ This is for defining lambda functions also called anonymous functions (this is a concept applicable to many programming languages). . In this context, the "dot" represents each one of the columns you have selected with the contains("d") selection helper.