报错如下
In if (nchar(id) == 18) substr(id, 7, 14) else paste("19", substr(id, :
the condition has length > 1 and only the first element will be used
我使用的代码是这个
sapply(data[,1],afunc)
afunc<-function(id){
if(nchar(id)==15)
paste('19',substr(id,7,12),sep="")
else
substr(id,7,14)
}
源数据是这样的
身份证号 调查日期 出现次数 身份证合法
320521197105053000 2010/5/1 1 合法
350127194703133000 2010/4/30 1 合法
320503511110254 2010/5/1 1 合法
320504371115153 2010/5/1 1 合法
320502196201222000 2010/5/1 1 合法
320525195603122000 2010/5/1 1 合法
510702197306050000 2010/5/1 1 合法
350121197403245000 2010/4/30 1 合法
510723196810201000 2010/5/1 1 合法
NA 2010/5/1 1 NA
321002194504101000 2011/6/28 1 合法