[R] Not seeing the results of a function

David p@rkhur@ @end|ng |rom |nd|@n@@edu
Sun Mar 29 20:55:44 CEST 2020


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



More information about the R-help mailing list