[R] Adding values to the end of a data frame
Dennis Murphy
djmuser at gmail.com
Wed Jun 8 02:54:05 CEST 2011
Alas, you don't have a suffix2 object defined, but try this:
d1 <- one(prefix, roots)
d2 <- one(roots, suffix)
rbind(d1, d2)
To see a potential flaw in your function (as least as far as console
output is concerned), try
rbind(d1, one(roots, suffix))
HTH,
Dennis
On Tue, Jun 7, 2011 at 3:30 PM, Abraham Mathew <abraham at thisorthat.com> wrote:
> Let's say that I'm trying to write a functions that will allow me to
> automate a process
> where I examine all possible combinations of various string groupings. Each
> time I run
> the one function, I want to include the new values to the end of a data
> frame. The data
> frame will basically be one column with a lot of rows.
>
> roots <- c("car insurance", "auto insurance")
> prefix <- c("cheap", "budget")
> suffix <- c("rate", "rates")
>
> one <- function(x, y, z=0) {
> nu <- do.call(paste, expand.grid(x, y, z))
> mydf <- data.frame(nu)
> print(mydf)
> }
>
> one(roots, suffix2)
> one(prefix, roots)
> one(prefix, roots, suffix2)
>
> The code above just replaces each value in the data frame each time I run
> the one function.
>
> How can I add the new values to the end of the data frame?
>
>
> Help!
>
> I'm running R 2.13 on Ubuntu 10.10
> WebRep
> Overall rating
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list