EDIT: I just looked at some more ZIP codes in my file, and learned it is a leading zero these codes are missing.
I have a bunch of zip codes formatted like:
zip
8974
8974
4350
4350
7623
55111
98769
As you can see, these are missing the last 0
to meet the 5-digit ZIP code requirement, because of a formatting issue.
I'm trying to do this:
attach(dat)
for(x in zip){
if(nchar(x) < 5){
x <- x*10
}
}
I've also tried this:
for(x in zip){
if(nchar(x) < 5){
zip[x] <- x*10
}
}
But neither produce the desired result. How can I add the zero to these ZIP codes in R?