qoiqpwqr 发表于 2011-9-30 12:07 
我的程序里面的dat必须是大小为n x 1的data frame
谢谢!
可以了。
另外请问:
功能类同于nchar函数,
但针对数值变量的是哪个函数?
card= read.csv(file="CARD.csv", hearder=TRUE, sep=",")
n=length(card) #n==78
mode(card) # list
mode(id) # numeric
id[1:10]
###[1] ‘13294497’ ‘20455648’ ‘-148209’ ‘8661261’ ‘24742283’ ‘15966960’
[7] ‘-150598’ ‘18323141’ ‘11718213’ ‘20574307’
idd=id
mode(idd) # numeric
n=length(idd) #21900
iddd=as.matrix(idd)
dim(iddd)
[1] 21900 1
iddd[1:10]
[1] "‘13294497’" "‘20455648’" "‘-148209’" "‘8661261’" "‘24742283’"
[6] "‘15966960’" "‘-150598’" "‘18323141’" "‘11718213’" "‘20574307’"
> removeQuote <- function(iddd) substr(iddd, 2, nchar(iddd) -1)
> aa=apply(iddd, 1, removeQuote) 警告信息:
In aperm.default(X, c(s.call, s.ans)) :
Reached total allocation of 1535Mb: see help(memory.size)
> aa[1:10]
[1] "13294497" "20455648" "-148209" "8661261" "24742283" "15966960"
[7] "-150598" "18323141" "11718213" "20574307"
> mode(aa)
[1] "character"
> length(aa)
[1] 21900
> aanumeric=as.numeric(aa)
> aanumeric[1:10]
[1] 13294497 20455648 -148209 8661261 24742283 15966960 -150598 18323141
[9] 11718213 20574307