[R] grouping data
Joshua Wiley
jwiley.psych at gmail.com
Sat Mar 5 03:52:39 CET 2011
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/
More information about the R-help
mailing list