0

I'm new to the site and hopefully this will be an easy questions for an experience R developer. I am currently passing over three sets of columns as variables, 1 set of "CenterCode" and 2 sets of zipcodes "Postal Code". Center Code would always be the same value for the entire column. ideally, i would want the outcome should be something like this:

> CenterCode ServiceaArea PostalCode
> center_1   SA_1         12345
> center_1   SA_2         56789

However, my current Code produces the correct zip codes tied with the correct Service area but separates the PostalCodes into two columns e.g.

> CenterCode ServiceaArea pCcodePSA pCodeCPA
> center_1   SA_1         12345     NA
> center_1   SA_2         NA        56789

My Code is as follows:

pCodePSA <- zipCodePSA
pCodeCPA <- zipCodeCPA
cCode <- CenterCode


zipPSATable <- data.frame(pCodePSA)
zipPSATable$CenterCode <- cCode
zipPSATable$serviceArea <- "SA_1"

zipCPATable <- data.frame(pCodeCPA)
zipCPATable$CenterCode <- cCode
zipCPATable$serviceArea <- "SA_2"


zipTable <- merge(zipPSATable , zipCPATable,all=TRUE)
zipTable

Can any help with combinig the pCodes into one column as PostalCode and removing the NAs?

Edgar
  • 9
  • 1

0 Answers0