Friday, 22 March 2013

Creating new variables with R

# Three examples for doing the same computations

mydata$sum <- br="" mydata="" x1="" x2=""> mydata$mean <- br="" mydata="" x1="" x2="">
attach(mydata)
mydata$sum <- br="" x1="" x2=""> mydata$mean <- br="" x1="" x2=""> detach(mydata)

mydata <- br="" mydata="" transform=""> sum = x1 + x2,
mean = (x1 + x2)/2


Source for the above code.