Reputation: 4346
Building on this question: dplyr: how to reference columns by column index rather than column name using mutate?
I want to mutate using column indexes for both the source and the destination of the mutate:
iris %>% head %>% mutate(.[[1]] = .[[1]] + .[[2]])
gives:
Error: unexpected '=' in "iris %>% head %>% mutate(.[[1]] =".
However, the following works:
iris %>% head %>% mutate(sum = .[[1]] + .[[2]])
Upvotes: 9
Views: 9556