Modifying Vectors in R – Example Code

In this example, we have created a vector X and later changed all values of vector x>10 = 4.

 

> x <- c(17, 14, 4, 5, 13, 12, 10)
> x[x>10]
[1] 17 14 13 12
> x
[1] 17 14 4 5 13 12 10
> x[x>10]<-4
> x
[1] 4 4 4 5 4 4 10

Leave a Comment

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