'a' and 'b' are vectors of length 100, so the sum of them would also produce a vector of 100. So in one case, your code should look like this:
> a<-replicate(5, rnorm(20)) > b<-replicate(5, rnorm(20)) > > xyz<-function(x,y){ + z<-x+y + print(paste("the sum of", x, "and", y,"is", z, sep=" ")) + } > > xyz(a,b) [1] "the sum of 0.078437532748926 and 1.42398359867007 is 1.502421131419" [2] "the sum of -0.779261070429696 and 0.484730511200338 is -0.294530559229357" [3] "the sum of 0.16655966873187 and 0.349236445934426 is 0.515796114666296" [4] "the sum of 0.265324569774749 and 0.860124249616191 is 1.12544881939094" [5] "the sum of 0.890780709620268 and 0.404611144608053 is 1.29539185422832" [6] "the sum of -0.467888369466512 and 0.367044921399527 is -0.100843448066985" [7] "the sum of 0.758374556806851 and -1.51919904950798 is -0.760824492701126" ......... Is this your expected output? If not, give a clear example of what you are expecting. Could it be: > sum(a + b) [1] 16.90667 On Wed, Jun 19, 2013 at 8:16 PM, Thomas Parr <thomas.p...@maine.edu> wrote: > I am writing a function and I would like to return the name of a data frame > in a paste call, but I can't figure out how to just get the name. The names > of the data frames used, won't be the same each time. I have to be > overlooking the obvious. > > #For example: > > a<-replicate(5, rnorm(20)) > b<-replicate(5, rnorm(20)) > > xyz<-function(x,y){ > z<-x+y > print(paste("the sum of", x, "and", y,"is", sep=" ")) > z > } > > xyz(a,b) > > #That function should return: > > >"the sum of a and b is:" > >.and some data. > > Not surprisingly, it returns all the data in the data frame. > > Thanks, > Thomas > > ______________________________________________ > R-help@r-project.org mailing list > 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. > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list 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.