This function is created to fix problems caused by a serious bug in Excel. Editing csv files in that program causes leading zeros to disappear.
AddLeadingZeros(
codes,
places,
warningText = NULL,
viaFactor = TRUE,
nWarning = 6,
removeLeadingTrailingWhitespace = TRUE
)
Character vector
Character vector
Number of places for positive numbers. Minus sign is extra
When non-NULL, warning will be produced
When TRUE, the algorithm uses factor coding internally.
Number of elements to be written before ... in warnings.
Remove leading and trailing whitespace
Øyvind Langsrud
AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007",
"7 James Bond "), 10)
AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007",
"7 James Bond "), 4)
AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007",
"7 James Bond "), 4, removeLeadingTrailingWhitespace = FALSE)
AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007",
"7 James Bond "), 4, warningText = "string changes")
AddLeadingZeros(c("1", "ABC", "12345", " 23", "-8", "45 ", " -9", " Agent ", "007",
"7 James Bond "), 4, warningText = "", nWarning = 2)
Run the code above in your browser using DataLab