Re: [R] grouping data

From: Joshua Wiley <jwiley.psych_at_gmail.com>
Date: Fri, 04 Mar 2011 18:52:39 -0800

Hi Steve,

Just test whether y is greater than the predicted y (i.e., your line).

## function using the model coefficients* f <- function(x) {82.9996 + (.5589 * x)} ## Find group membership
group <- ifelse(y > foo(x), "A", "B")

*Note that depending how accurate this needs to be, you will probably want to use the model itself rather than just reading from the printout like I did. If you need to do that, take a look at ?predict

For future reference, it would be easier for readers if you provided your data via something like: dput(x) that can be copied directly into the R console. Also, if you are generating random data (rnorm()), you can use set.seed() so that we can replicate exactly what you get.

HTH, Josh

On Fri, Mar 4, 2011 at 1:39 PM, Steve Hong <emptican_at_gmail.com> wrote:
> Hi R-list,
>
> I have a data set with plot locations and observations and want to label
> them based on locations.  For example, I have GPS information (x and y) as
> follows:
[snip]
>> (fm1 <- lm(ysim~xsim))
> Call:
> lm(formula = ysim ~ xsim)
> Coefficients:
> (Intercept)         xsim
>    82.9996       0.5589
>
> I overlapped fitted line on the plot.
>
>> abline(fm1)
> My question is:
> As you can see in the plot, how can I label (or re-group) those in upper
> diagonal as (say) 'A' and the others in lower diagonal as 'B'?
>
> Thanks a lot in advance!!!
>
> Steve
>
>        [[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.
>

-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/

______________________________________________
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.
Received on Sat 05 Mar 2011 - 02:57:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 16 Mar 2011 - 06:10:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive