I am new to coding and I am learning the basics of R. I have a data set that I made in Excel. They are Zip codes; however, zip codes starting with 0 automatically eliminated when exporting. I am attempting to iterate through and add the 0 back.
My thoughts were, assuming that the zip codes w/o an initial zero are 4 characters long, I simply find the iterations that have length of 4 and then add a 0 to the front, but I am not getting the right answer.
zip<-c(61415, 19087, 63122, 3104, 1938)
zip<-as.character(zip)
>for(i in zip){
+
+if(nchar(i)==4){
+ paste0("0",i)
+ }
+ }
NULL
I should get:
"61415", "19087", "63122", "03104", "01938"