Graphing a piece-wise defined function in RKward
meik michalke
meik.michalke at uni-duesseldorf.de
Mon Dec 19 14:58:48 UTC 2016
hi michael,
Am Montag, 19. Dezember 2016, 09:26:09 CET schrieb Philip (Michael) Dykes:
> I am very new to both R and Rkward and am trying to plot the following:
>
> f(x)= x^2, if x <= 2,
> 6-x, if x > 2.
>
> How can I do this in Rkward? Also, I would like the graph (plot) to look
> as much as possible like the graph I was in this book (attached).
this is a very basic R question, and general R support is far beyond the scope
if this mailing list (and, well, you should not send attachments to mailing
lists).
but FWIW, here's a hint to get you a little closer to what you want to
achieve:
piecewise <- function(x){
if(x <= 2){
y <- x^2
} else {
y <- 6-x
}
return(y)
}
plot(sapply(-3:6, piecewise))
you should try to work yourself through some basic R tutorials, there's a lot
of them out there on the web ;-)
viele grüße :: m.eik
--
dipl. psych. meik michalke
institut f"ur experimentelle psychologie
abt. f"ur diagnostik und differentielle psychologie
heinrich-heine-universit"at d-40204 d"usseldorf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/rkward-users/attachments/20161219/70bc8b82/attachment.sig>
More information about the rkward-users
mailing list