I have some idea as to how to select columns using .[] and .$ in dplyr.
Here is a reprex:-
library(dplyr)
> mtcars%>% .["disp"] %>% head
disp
Mazda RX4 160
Mazda RX4 Wag 160
Datsun 710 108
Hornet 4 Drive 258
Hornet Sportabout 360
Valiant 225
> mtcars%>% .$"disp" %>% head
[1] 160 160 108 258 360 225
>
I wish to read the help page the .[] and .$ How can I do this ? My googling was not successful so I came here. Can someone point me in the right direction ?
I am using this inside mutate.
> library(dplyr)
> names(mtcars)
[1] "mpg" "cyl" "disp" "hp" "drat" "wt" "qsec" "vs" "am" "gear"
[11] "carb"
> chosen_cols <- c("disp","drat")
> library(dplyr)
> mtcars %>% mutate(answer = rowSums(.[chosen_cols]))
Here is how we can select rows :-
mtcars %>% head %>% .[1,]
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21 6 160 110 3.9 2.62 16.46 0 1 4 4
>