performing calculation by calling values with .$ and .[ ]

Viewed 42

This is purely a conceptual question, but how could I refer to the elements of my vector c(2,3) in a calculation using .$ or .[]?

library(tidyverse)

c(2, 3) %>% 
  .[1] * .[2]

This code works fine but requires a temporary object (v) to be created:

v <- c(2,3)
v[1] * v[2]

And I'd like to know how to perform the calculation in the tidyverse without creating the temporary object v.

1 Answers
Related