Hi Jan,
You can do it in two ways.  The simplest one is the following.

The first option is to use $.  Here is how:
dogs <- data.frame(a = 1:10, b = 10:1)
dogs$c <- dogs$a+dogs$b
dogs


The second way it to use
?within


----------------Contact
Details:-------------------------------------------------------
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
----------------------------------------------------------------------------------------------




On Thu, Jun 28, 2012 at 12:10 PM, Jan Näs <j...@plattfot.com> wrote:

> Hi
>
> Newbie question:
>
> I have a set of data frames that I want to do the same calculations on
> each.
> I've found out that I can put them in a list and loop through the list
> to do the calculation, but not put the results back into each
> data.frame..
>
> For example three data frames cats, dogs, birds
>
> where >cats
>
> name eats_kg
> 1 bob 3
> 2 garfield 4
> 3 chuck 6
>
> and dogs and birds are similar but not same length.
>
> On each data frame I now want to add a column with cost of food by
> calculating "eats_kg"*price of food.
>
> So question is, can I put all data frames into one loop which returns
> a new column for each?
>
> Ive tried
>
> MyList <- list(cast,dog,birds)
>
> for(i in 1:length(MyList)){
> price <- as.data.frame(myList[i])[,2] * cost
> .. and then Im stuck. How can I put "price" back into each data frame?
>
> Thanks in advance.
>
> ______________________________________________
> 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.
>

        [[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.

Reply via email to