How to Calculate the Square of a Vector in R (Example Code)
In this R tutorial you’ll learn how to raise the values of a data object to the power of two.
Creation of Exemplifying Data
x <- 10:15 # Creating vector object in R x # Printing vector object to RStudio console # [1] 10 11 12 13 14 15 |
x <- 10:15 # Creating vector object in R x # Printing vector object to RStudio console # [1] 10 11 12 13 14 15
Example: Taking Vector Objects to the Power of Two
x^2 # Raising x to the power of two # [1] 100 121 144 169 196 225 |
x^2 # Raising x to the power of two # [1] 100 121 144 169 196 225