Dear R-users
Thanks for all the help/suggestions, they have been most helpful.
Best regards
Pryseley
-
[[alternative HTML version deleted]]
__
Hello R-users
I am new to R and trying to write some functions. I have problems writing
functions that takes a data set as an arguement and uses variables in the data.
I illustrate my problem with a small example below:
sample data #--
visual24-rnorm(30,3,5)
],rcc[2])
detach(data)
}
st(dats,visual24,visual52)
Best,
Matthias
-Ursprüngliche Nachricht-
Von: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Im Auftrag von
Pryseley Assam
Gesendet: Montag, 30. Jänner 2006 14:14
An: r-help@stat.math.ethz.ch
Betreff: [R] Help with R
# Here it is (using the formula interface):
dats - data.frame(visual24 = rnorm(30, 3, 5),
visual52 = rt(30, 7))
st - function(formula, data, ...) {
# Just use the formula to specify which variables to use
rcc - coef(lm(formula, data))
# Make sure to
st - function(data, x, y){
attach(data)
rcc - coef(lm(y~x))
plot(x,y)
abline(rcc)
detach(data)}
st(data=dats, x=visual24, y=visual52)
Pryseley Assam a écrit :
Hello R-users
I am new to R and trying to write some functions. I have problems writing
functions that
This might be a bit closer to what Pryseley wanted:
st - function(dat, x, y) {
f - formula(substitute(y ~ x), env=environment(dat))
plot(f, dat)
abline(lm(f, dat))
}
Note that the variable names in the plot when tested on `dats' as Pryseley
created.
Andy
From: Jacques VESLOT
st