2011年4月28日星期四

print out R vector object as sequence

# example code
x<-1:10
paste(x, sep="", collapse=",")

# output
# Note using paste() you can get different print of the vector object,
# Pls, compare these two
> paste(x, sep="", collapse=",") 
[1] "1,2,3,4,5,6,7,8,9,10"
> x 
[1]  1  2  3  4  5  6  7  8  9 10
 
##########################################
Rvector = function(vector) {
out = paste("c(",paste(x, sep="", collapse=","),")",sep="")
cat("\n",out,"\n","\n")
return(out)
}

Rmatrix = function(matrix) {
out = paste("matrix(", Rvector(as.matrix(mat)), "," ,nrow(mat), ",", ncol(mat), ")", sep="")
cat("\n",out,"\n","\n")
return(out)
} 

没有评论:

发表评论