Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Reference the new column with the $ operator, and assign
some values to it. For this example, we’ll use a copy of the heightweight data set:
library(gcookbook)# For the data set# Make a copy of the datahw<-heightweight hwsex ageYear ageMonth heightIn weightLb f11.9214356.385.0f12.9215562.3105.0...m13.9216762.0107.5m12.5815159.387.0
This will convert heightIn
to centimeters and store it in a new column, heightCm:
hw$heightCm<-hw$heightIn*2.54hwsex ageYear ageMonth heightIn weightLb heightCm f11.9214356.385.0143.002f12.9215562.3105.0158.242...m13.9216762.0107.5157.480m12.5815159.387.0150.622