質問

There are several questions:

1 In an R function, "return" only can output one plot or value. But now, I want the function output every plot or vector I require, how could I achieve that. Which code should I use.

2 I have a series of variables : Game1~Game10 and I built up a do loop to analysis each of them where I represented their name as
"paste("Game",i, sep="")",
But it is characters, and I cannot do it like a variable like
"sort(eval(paste("Game",i, sep="")))"
is fail. How could I make R recognize the characters series as a variable name.

役に立ちましたか?

解決

to return more than one value from a function, use a data structure, that can store more values and return it, e.g. a vector, list or a dataframe

...
vector_1 <- 1:10
vector_2 <- 11:20
return( list(vec_1=vector_1, vec_2=vector_2) )

to output more than one plot, simply use a loop within the function e.g.

for(i in 5:10) plot(1:i)

Your second question is not clear to me. What are you trying to do?

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top