我必须在52/200005/0001(必须忽略斜线)的数字上添加一个2位数的支票(除97除外)。如何计算R中大数的校验位?
我的代码是下面的,但它失败,因为太多大数目:
AppendCheckDigits <- function (x) {
stopifnot(is.character(x) & length(x) == 1 & nchar(x) == 14)
cd <- as.integer(paste(substring(x, 1, 2),
substring(x, 4, 9),
substring(x, 11, 14), sep="")) %% 97
paste(x, "/", cd, sep="")
}
测试它:
AppendCheckDigits("52/200005/0001")
我怎样才能解决呢?
我还能说什么比“我没有期待这样一个完美的答案,清晰而广泛”?不知道! ;-) – user3341592 2014-10-03 15:12:08
代码AppendCheckDigits < - function(x){stoplexnot(is.character(x)&nchar(x)== 14) num < - as.numeric(gsub(“/”,“”,x ))%% 97 paste0(x,“/”,num)似乎和你一样工作。这里没有“rep”,也没有“return”。他们真的很重要吗? } – user3341592 2014-10-03 15:28:28
@ user3341592不,你说得对,使用回收规则时不需要在这里使用'rep'。你的代码很好,更干净。 – juba 2014-10-03 18:39:21