Simple one

4 messages Options
Embed this post
Permalink
JoK LoQ

Simple one

Reply Threaded More More options
Print post
Permalink
Just a quickly beginner's question.

I wanna find the mean only from the values from a column related to specific values from another one. Like, theres a 'region' column, i want the mean of the value on 'profit' column only from "south" sells from 'region' column
Ben Bolker

Re: Simple one

Reply Threaded More More options
Print post
Permalink

JoK LoQ wrote:
Just a quickly beginner's question.

I wanna find the mean only from the values from a column related to specific values from another one. Like, theres a 'region' column, i want the mean of the value on 'profit' column only from "south" sells from 'region' column
mean(x[x$region=="south",]$profit)

or  (untested)

mean(subset(x,region=="south",select=profit))
jholtman

Re: Simple one

Reply Threaded More More options
Print post
Permalink
In reply to this post by JoK LoQ
mean(x[x[,'region'] == 'south', 'profit'])

or if dataframe

mean(x$profit[x$region == 'south'])

or for all regions

tapply(x$profit, x$region, mean)

On Fri, Jul 3, 2009 at 6:55 PM, JoK LoQ<[hidden email]> wrote:

>
> Just a quickly beginner's question.
>
> I wanna find the mean only from the values from a column related to specific
> values from another one. Like, theres a 'region' column, i want the mean of
> the value on 'profit' column only from "south" sells from 'region' column
> --
> View this message in context: http://www.nabble.com/Simple-one-tp24329691p24329691.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] 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
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

______________________________________________
[hidden email] 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.
JoK LoQ

Re: Simple one

Reply Threaded More More options
Print post
Permalink
In reply to this post by Ben Bolker
Ben

 that subset(..) works, and it solves all my problems. thnks!


Ben Bolker wrote:
JoK LoQ wrote:
Just a quickly beginner's question.

I wanna find the mean only from the values from a column related to specific values from another one. Like, theres a 'region' column, i want the mean of the value on 'profit' column only from "south" sells from 'region' column
mean(x[x$region=="south",]$profit)

or  (untested)

mean(subset(x,region=="south",select=profit))