Simple one

View: New views
4 Messages — Rating Filter:   Alert me  

Simple one

by JoK LoQ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Simple one

by Ben Bolker :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


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))

Re: Simple one

by jholtman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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<jokloq@...> 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.
>
> ______________________________________________
> R-help@... 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?

______________________________________________
R-help@... 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.

Re: Simple one

by JoK LoQ :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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))