I believe this should be an easy thing to do... I have a function I repeatably call which takes input parameters and outputs columns to various data frames. I also wish to keep a summary of certain values as I call the function. I though keeping the values in a vector then appending the vector by the new amounts would be the way to do this. Example: (this is what I want even thought the below syntax is wrong) a <- 1 print(a) --> 1 a <- c(a,2) print(a) --> 1,2 a <- c(a,2,4,5) print(a) --> 1,2,2,4,5 Any help would be greatly appreciated... Marko -- Mark O. Kimball Gasparinilab, University of Buffalo | Low temp physics mok2 at physics.buffalo.edu | URL: enthalpy.physics.buffalo.edu lab phone: 716-645-2017x122 Fax: 716-645-2507
Marko, Looks fine to me. Why do you think the syntax is incorrect? Works for me in 1.8 on Windows.> a <- 1 > a[1] 1> a <- c(a,2) > a[1] 1 2> a <- c(a,2,4,5) > a[1] 1 2 2 4 5>steve -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Mark O. Kimball Sent: Friday, April 02, 2004 4:27 PM To: r-help at stat.math.ethz.ch Subject: [R] Extending a vector I believe this should be an easy thing to do... I have a function I repeatably call which takes input parameters and outputs columns to various data frames. I also wish to keep a summary of certain values as I call the function. I though keeping the values in a vector then appending the vector by the new amounts would be the way to do this. Example: (this is what I want even thought the below syntax is wrong) a <- 1 print(a) --> 1 a <- c(a,2) print(a) --> 1,2 a <- c(a,2,4,5) print(a) --> 1,2,2,4,5 Any help would be greatly appreciated... Marko -- Mark O. Kimball Gasparinilab, University of Buffalo | Low temp physics mok2 at physics.buffalo.edu | URL: enthalpy.physics.buffalo.edu lab phone: 716-645-2017x122 Fax: 716-645-2507 ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>Marko,>Looks fine to me. Why do you think the syntax is incorrect? Works for me in >1.8 on Windows.> I have a function I repeatably call which takes input parameters and > outputs columns to various data frames.Looks fine to me although it is not completely clear that your request for column and "pseudocode"your syntax match. To make a into a column vector try a transpose: t(a) This should line up with a dataframe column in whatever logic you use in the function (which you did not explain to uw) HTH, Rob Baer
On Friday 02 April 2004 04:52 pm, you wrote:>> I believe this should be an easy thing to do... >> >> I have a function I repeatably call which takes input parameters and >> outputs columns to various data frames. I also wish to keep a summary >> of >> certain values as I call the function. I though keeping the values in >> a >> vector then appending the vector by the new amounts would be the way >> to >> do this. >> >> Example: (this is what I want even thought the below syntax is wrong) >> >> a <- 1 >> print(a) --> 1 >> >> a <- c(a,2) >> print(a) --> 1,2 >> >> a <- c(a,2,4,5) >> print(a) --> 1,2,2,4,5 >> >> Any help would be greatly appreciated...> > Looks fine to me. Why do you think the syntax is incorrect? Works for > me in > 1.8 on Windows. > > > a <- 1 > > a > > [1] 1 > > > a <- c(a,2) > > a > > [1] 1 2 > > > a <- c(a,2,4,5) > > a > > [1] 1 2 2 4 5 > > > steveEntirely my fault... I forgot about the function scope rules and needed to use: vector <<- stuff to add instead of: vector <- stuff to add Thanks for the help... Marko -- Mark O. Kimball Gasparinilab, University of Buffalo | Low temp physics mok2 at physics.buffalo.edu | URL: enthalpy.physics.buffalo.edu lab phone: 716-645-2017x122 Fax: 716-645-2507
There is a problem with this scheme that has nothing to do with syntax. Extending objects dynamically like this is probably the surest way to run out of memory. If you know the final length an object will be, then it is best to create the object at its full length and then subscript into it with assignments. In this application you apparently don't know what the final length will be. In this case you can create an object of some length, subscript into it with assignments (keeping track of how much has gone in), then grow the object again by some chunk when more room is needed. Patrick Burns Burns Statistics patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") Mark O. Kimball wrote:>I believe this should be an easy thing to do... > >I have a function I repeatably call which takes input parameters and >outputs columns to various data frames. I also wish to keep a summary of >certain values as I call the function. I though keeping the values in a >vector then appending the vector by the new amounts would be the way to >do this. > >Example: (this is what I want even thought the below syntax is wrong) > >a <- 1 >print(a) --> 1 > >a <- c(a,2) >print(a) --> 1,2 > >a <- c(a,2,4,5) >print(a) --> 1,2,2,4,5 > >Any help would be greatly appreciated... > >Marko > >