R for Spatial Statistics

 

Converting Columns

One of the things we do regularly is convert columns of values (often attributes in spatial data) to other types of data.

Generating Curves

Code below will convert a numeric value to a boolean vector and then into a numeric vector so we can have 0s and 1s to work with in our table.

# Convert an attribute (vector column) to numeric
BooleanValues=TheCities$CITY_ID>0
NumericValues=as.numeric(BooleanValues)
TheCities=data.frame(TheCities,NumericValues) # add the numeric (0s and 1s) into the dataframe

We can also convert columns to factors. Factors are used when we have text string that need to be treated as numbers.

# Convert an attribute (vector column) to factor
FactorValues=as.factor(TheCities$NAME)
TheCities=data.frame(TheCities,FactorValues)

 

Other Resources