问题
I am trying to make staircase of given length n using the following function:
hash<-function(n){
for (i in 1:n){
v1=c()
#j=1
for (j in 1:i){
v1=paste("#",v1,sep="")
}
cat(v1,"\n")
}
}
But I want it right aligned. What I am getting is:
#
##
###
####
#####
######
I was wondering, can I get some help how to make it aligned the other way?thanks for the assistance.
回答1:
n=6
for (i in 1:n) {
v1=c()
v2=c()
for (j in i:n-1) {
v1=paste(" ",v1,sep="")
}
for (k in i:1) {
v2=paste("#",v2,sep="")
}
cat(v1,v2,"\n")
}
来源:https://stackoverflow.com/questions/40962641/change-the-alignment-of-the-staircase-in-r