Exercise15

Maggie Hallerud

October 31, 2017

Import bearclawpoppy dataset

setwd("~/WILD4580/data/exercise_dat") # set working directory
poppy<-read.csv("bearclawpoppy.csv")
names(poppy)
##  [1] "UNIQUE_ID"  "PLANT"      "Raster_ID"  "UTM_East"   "UTM_North" 
##  [6] "flag"       "SURVEY"     "SOIL"       "VEG_SYMBOL" "ELEV"      
## [11] "SLOPE"      "ASPECT"     "GEOLOGY"    "DATE_"      "LANDFORM"  
## [16] "PARENT_MA"  "PEN"        "PEN_SIZE"   "SHEAR"      "SHEAR_S"   
## [21] "B_CRUST"    "P_CRUST"    "ROCK_"      "R_TYPE"     "surveytype"
## [26] "penvalue"   "prec_pc1"   "prec_pc2"   "sdir_pc1"   "srad_pc1"  
## [31] "tmax_pc1"   "tmin_pc1"   "vpam_pc1"   "pH"         "Eff_Cl"    
## [36] "RF_Cl"      "Text_Cl"    "Clay"       "ECe"        "Gypsum"    
## [41] "BD"         "Calc_Fr"

Condensing landform variable according to rules

poppy$LANDFORM<-as.character(poppy$LANDFORM) #corrects error of conversion to factor
poppy$LANDFORM <- ifelse(poppy$LANDFORM=="af"|poppy$LANDFORM=="aflb"|poppy$LANDFORM=="afub"|poppy$LANDFORM=="afwb"|poppy$LANDFORM=="afws","af_type",poppy$LANDFORM)
poppy$LANDFORM<-as.character(poppy$LANDFORM) #corrects error of conversion to factor
poppy$LANDFORM <- ifelse(poppy$LANDFORM=="bfr"|poppy$LANDFORM=="bfrlb"|poppy$LANDFORM=="bfrwb"|poppy$LANDFORM=="bfrbws"|poppy$LANDFORM=="bfrws","bf_type",poppy$LANDFORM)
poppy$LANDFORM<-as.character(poppy$LANDFORM) #corrects error of conversion to factor
poppy$LANDFORM <- ifelse(poppy$LANDFORM=="lb"|poppy$LANDFORM=="lbaf"|poppy$LANDFORM=="lbub"|poppy$LANDFORM=="lbwb","lb_type",poppy$LANDFORM)
poppy$LANDFORM<-as.character(poppy$LANDFORM) #corrects error of conversion to factor
poppy$LANDFORM <- ifelse(poppy$LANDFORM=="wb"|poppy$LANDFORM=="wblb"|poppy$LANDFORM=="wbub"|poppy$LANDFORM=="wbws"|poppy$LANDFORM=="ws"|poppy$LANDFORM=="wslb","ws_type",poppy$LANDFORM)
poppy$LANDFORM<-as.character(poppy$LANDFORM) #corrects error of conversion to factor
poppy$LANDFORM <- ifelse(poppy$LANDFORM==""|poppy$LANDFORM=="99","NA",poppy$LANDFORM)
poppy$LANDFORM
##   [1] "lb_type" "lb_type" "lb_type" "bf_type" "lb_type" "lb_type" "lb_type"
##   [8] "lb_type" "lb_type" "lb_type" "lb_type" "lb_type" "lb_type" "lb_type"
##  [15] "lb_type" "lb_type" "ws_type" "ws_type" "lb_type" "lb_type" "lb_type"
##  [22] "lb_type" "lb_type" "lb_type" "lb_type" "lb_type" "lb_type" "lb_type"
##  [29] "af_type" "af_type" "lb_type" "lb_type" "lb_type" "lb_type" "ws_type"
##  [36] "ws_type" "ws_type" "ws_type" "ws_type" "ws_type" "ws_type" "ws_type"
##  [43] "ws_type" "ws_type" "ws_type" "ws_type" "ws_type" "af_type" "af_type"
##  [50] "af_type" "af_type" "af_type" "lb_type" "ws_type" "ws_type" "lb_type"
##  [57] "lb_type" "lb_type" "lb_type" "ws_type" "ws_type" "ws_type" "bf_type"
##  [64] "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type"
##  [71] "bf_type" "bfrwbws" "bfrwbws" "ws_type" "bf_type" "bf_type" "ws_type"
##  [78] "ws_type" "ws_type" "ws_type" "ws_type" "ws_type" "bf_type" "bf_type"
##  [85] "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type"
##  [92] "bf_type" "bf_type" "bf_type" "ws_type" "ws_type" "ws_type" "ws_type"
##  [99] "ws_type" "ws_type" "ws_type" "NA"      "NA"      "lb_type" "lb_type"
## [106] "lb_type" "lb_type" "ws_type" "bf_type" "ws_type" "bf_type" "bf_type"
## [113] "bf_type" "bf_type" "ub"      "ub"      "lb_type" "lb_type" "lb_type"
## [120] "af_type" "af_type" "ws_type" "ws_type" "bf_type" "bf_type" "bf_type"
## [127] "bf_type" "bf_type" "ws_type" "ws_type" "bf_type" "bf_type" "bf_type"
## [134] "ub"      "ub"      "ub"      "lb_type" "lb_type" "lb_type" "lb_type"
## [141] "ws_type" "ws_type" "bf_type" "ws_type" "bf_type" "bf_type" "bf_type"
## [148] "ub"      "ub"      "lb_type" "lb_type" "lb_type" "lb_type" "ub"     
## [155] "ub"      "lb_type" "lb_type" "lb_type" "lb_type" "ub"      "ws_type"
## [162] "af_type" "ub"      "af_type" "lb_type" "bf_type" "bf_type" "bf_type"
## [169] "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "ws_type" "lb_type"
## [176] "bf_type" "bf_type" "lb_type" "NA"      "bf_type" "ws_type" "bf_type"
## [183] "bf_type" "ws_type" "ws_type" "bf_type" "bf_type" "bf_type" "bf_type"
## [190] "bf_type" "ws_type" "bf_type" "bf_type" "bf_type" "bf_type" "ws_type"
## [197] "bf_type" "lb_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type"
## [204] "bf_type" "ws_type" "lb_type" "lb_type" "?"       "bf_type" "lb_type"
## [211] "ws_type" "bf_type" "bf_type" "bf_type" "ws_type" "ws_type" "bf_type"
## [218] "ws_type" "ws_type" "lb_type" "lb_type" "bf_type" "bf_type" "ws_type"
## [225] "lb_type" "lb_type" "ws_type" "ws_type" "bf_type" "lb_type" "bf_type"
## [232] "lb_type" "ws_type" "bf_type" "bf_type" "lb_type" "bf_type" "lb_type"
## [239] "ws_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "ws_type"
## [246] "ws_type" "bf_type" "bf_type" "bf_type" "bf_type" "ws_type" "bf_type"
## [253] "ws_type" "bf_type" "bf_type" "bf_type" "ws_type" "bf_type" "bf_type"
## [260] "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "ws_type" "bf_type"
## [267] "bf_type" "bf_type" "bf_type" "ws_type" "bf_type" "bf_type" "bf_type"
## [274] "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type"
## [281] "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type"
## [288] "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "ws_type"
## [295] "ws_type" "bf_type" "ws_type" "bf_type" "bf_type" "bf_type" "bf_type"
## [302] "ws_type" "bf_type" "ws_type" "ws_type" "ws_type" "bf_type" "bf_type"
## [309] "bf_type" "bf_type" "bf_type" "ws_type" "bf_type" "bf_type" "bf_type"
## [316] "bf_type" "ws_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type"
## [323] "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type"
## [330] "bf_type" "bf_type" "ws_type" "ws_type" "ws_type" "bf_type" "ws_type"
## [337] "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type" "bf_type"

Creating new variable presab where:

poppy$presab<-c(1:length(poppy$LANDFORM))
#ifelse(poppy$PLANT=='poppydead'|poppy$PLANT=='poppyalive'|poppy$PLANT=='poppy',poppy$presab#==1, ifelse(poppy$PLANT=='absence',poppy$presab==0), #ifelse(poppy$PLANT=='buckwheat',poppy$presab=='NA')) 

ifelse(poppy$PLANT=='poppydead'|poppy$PLANT=='poppyalive'|poppy$PLANT=='poppy',poppy$presab<-1, 
  ifelse(poppy$PLANT=='absence', poppy$presab<-0, 
    ifelse(poppy$PLANT=='buckwheat', poppy$presab<-'NA', poppy$presab<-'?')
      ))
##   [1] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
##  [15] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
##  [29] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
##  [43] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
##  [57] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
##  [71] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
##  [85] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
##  [99] "0"  "0"  "0"  "0"  "?"  "0"  "0"  "0"  "0"  "0"  "1"  "0"  "0"  "0" 
## [113] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "1"  "1" 
## [127] "1"  "NA" "NA" "1"  "0"  "0"  "NA" "0"  "0"  "0"  "0"  "0"  "0"  "0" 
## [141] "0"  "0"  "1"  "1"  "0"  "1"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
## [155] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
## [169] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "?"  "0"  "0"  "0" 
## [183] "0"  "0"  "1"  "0"  "0"  "0"  "NA" "0"  "0"  "0"  "1"  "0"  "0"  "1" 
## [197] "0"  "0"  "0"  "0"  "1"  "1"  "0"  "1"  "0"  "0"  "0"  "0"  "1"  "0" 
## [211] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
## [225] "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0"  "0" 
## [239] "0"  "0"  "0"  "0"  "0"  "1"  "0"  "1"  "0"  "0"  "1"  "0"  "1"  "1" 
## [253] "0"  "1"  "0"  "1"  "0"  "1"  "0"  "1"  "0"  "1"  "0"  "1"  "0"  "1" 
## [267] "0"  "1"  "0"  "1"  "0"  "1"  "0"  "1"  "0"  "1"  "0"  "NA" "0"  "NA"
## [281] "0"  "1"  "1"  "0"  "NA" "0"  "NA" "0"  "NA" "0"  "1"  "0"  "NA" "0" 
## [295] "1"  "1"  "0"  "0"  "1"  "0"  "1"  "0"  "1"  "0"  "1"  "0"  "1"  "0" 
## [309] "NA" "0"  "NA" "0"  "1"  "0"  "1"  "NA" "0"  "1"  "0"  "1"  "0"  "1" 
## [323] "0"  "1"  "0"  "0"  "1"  "0"  "0"  "1"  "0"  "1"  "0"  "1"  "0"  "0" 
## [337] "0"  "1"  "0"  "NA" "0"  "NA" "0"