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

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

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top