Below is the sample data. The task at hand is creating two new columns that would designate something by zip code. The first new column would be titled Las_Vegas and the second would be Laughlin. The first eight zip codes would have a value of 1 for Las Vegas and the second eight would have a value of 1 for Laughlin. The purpose of this is that I want to sum the employment for Las Vegas and Laughlin.
First question: Would it be best to use ifelse or case_when? Second question: Making the two new columns into defacto dummy variables... is this the best approach?
zipcode <-c(89102,89103,89104,89105,89106,89107,89108,89109,89110,89111,89112,89113,89114,89115,89116,89117)
naicstest<-c(541213,541213,541213,541213,541213,541213,541213,541213,541213,541213,541213,541213,541213,541212,541215,541214)
emptest <-c(2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32)
county <- data.frame(zipcode,naicstest,emptest)
End result. This end result would have sixteen rows. I kept it short for sake of simplicity. one row for Las_Vegas and one row for Laughlin. I know how to do the summarise (summing employment) but struggling how to make the two columns.
zipcode naicstest emptest Las_Vegas Laughlin
89102 541213 2 1 0
89110 541213 18 0 1
Aucun commentaire:
Enregistrer un commentaire