Reputation: 331
I would like to square every value in data
, and I am thinking about using a for loop like this:
data = rnorm(100, mean=0, sd=1)
Newdata = {L = NULL; for (i in data) {i = i*i} L = i return (L)}
Upvotes: 33
Views: 165179
Reputation: 1190
How about sapply
(not really necessary for this simple case):
newData<- sapply(data, function(x) x^2)
Upvotes: 9