[R] Not seeing the results of a function

Richard M. Heiberger rmh @end|ng |rom temp|e@edu
Mon Mar 30 16:45:19 CEST 2020


You need one more line In your function.

 addday <- function(stp,mcp,stpos,mcpos){
stpos<-c(stpos,stp)
mcpos<-c(mcpos,mcp)
days<-c(1:length(stpos))
list(mcpos=mcpos, days=days)
}

This and the other question I just answered together say that you need to
re-read an introduction to R.




On Mon, Mar 30, 2020 at 09:45 David <parkhurs using indiana.edu> wrote:

> I’m trying to write a function that will add items to two vectors, and
> then to create a third vector that is of the form 1, 2, 3, …, length of
> one of the newly modified vectors.  My problem is that what I’ve written
> doesn’t seem to return any of those modifications.  How can I get the
> new values to be returned? Here’s the function below.  I want to add a
> value, stp, to the end of the stpos vector, a value mcp to the end of
> the mcpos vector, and the to create that days vector.  When I call this
> function with numerical values for stp and mcp, and then ask to see
> stpos, mcpos, and days, nothing has been changed.  How can I fix this?
>
> Here’s the function:
>  > addday <- function(stp,mcp,stpos,mcpos){stpos<-c(stpos,stp)
> + mcpos<-c(mcpos,mcp)
> + days<-c(1:length(stpos))}
>
> David
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list