I am using R in a Windows environment.
I have a basic question regarding lm().
I have a dataframe data1 with ncol=w.
I know that my dependent variable is in column1.
Is there a way to write the regression formula so that
I can use columns 2 thru w as my independent
variables?
e.g.
Try:
lm(Sepal.Length ~., iris)
On 8/10/06, r user [EMAIL PROTECTED] wrote:
I am using R in a Windows environment.
I have a basic question regarding lm().
I have a dataframe data1 with ncol=w.
I know that my dependent variable is in column1.
Is there a way to write the regression formula
lm(data1) should work just fine. E.g.,
R data1 - data.frame(v1=rnorm(10), v2=rnorm(10), v3=rnorm(10))
R lm(data1)
Call:
lm(formula = data1)
Coefficients:
(Intercept) v2 v3
0.5746 0.3363 -0.5549
Andy
From: r user
I am using R in a Windows
You could look at using lm.fit instead of lm.
Alternatively, you can paste the names of the variables together using
the following approach. It's a bit baroque, but it works:
form.fn - function (dframe) {
nms - names(dframe)
formula(paste(nms[1], ~, paste(nms[2:length(nms)], collapse=+)))
}
I know this question is very simple, but I am not figure it out
I have the data frame:
test- data.frame(year=c(2000,2000,2001,2001),x=c(54,41,90,15),
y=c(29,2,92,22), z=c(26,68,46,51))
test
year x y z
1 2000 54 29 26
2 2000 41 2 68
3 2001 90 92
sapply(split(test, test$year), function(x) list(x.s = sum(x$x), y.s =
sum(x$y), z.s = sum(x$z)))
or for one variable only
aggregate(test$x, list(id = test$year), sum)
cheers
christoph
jose silva wrote:
I know this question is very simple, but I am not figure it out
I have the data frame:
On Thu, 2005-04-21 at 16:31 +0100, jose silva wrote:
I know this question is very simple, but I am not figure it out
I have the data frame:
test- data.frame(year=c(2000,2000,2001,2001),x=c(54,41,90,15),
y=c(29,2,92,22), z=c(26,68,46,51))
test
year x y z
1 2000 54 29 26
2 2000 41 2
snip
Oops...I forgot one more, using 'test.s' as per the prior e-mail:
test.s - split(test, test$year)
sapply(test.s, function(x) colSums(x[, -1]))
2000 2001
x 95 105
y 31 114
z 94 97
or transpose using t():
t(sapply(test.s, function(x) colSums(x[, -1])))
x y z
2000
On Wed, Feb 23, 2005 at 09:14:50PM -0500, rif wrote:
This does not do what the matlab code I posted does (the matlab code
also works in the free program octave, if you want to try). The
matlab code moves already plotted data within the window (replots it).
When I first type plot(1:10,1:10),
Is it possible to change the limits on plots that are already on the
screen? In particular, is there any R equivalent to the sequence of
matlab commands
plot(1:10,1:10)
hold on
plot(2:12,5:15)
I know I can use points and lines to add points and lines to plots,
but the limits of the plot do not
On Wed, 2005-02-23 at 17:42 -0500, rif wrote:
Is it possible to change the limits on plots that are already on the
screen? In particular, is there any R equivalent to the sequence of
matlab commands
plot(1:10,1:10)
hold on
plot(2:12,5:15)
I know I can use points and lines to add points
On Wed, 2005-02-23 at 17:42 -0500, rif wrote:
Is it possible to change the limits on plots that are already on the
screen? In particular, is there any R equivalent to the sequence of
matlab commands
plot(1:10,1:10)
hold on
plot(2:12,5:15)
rif
I have not used Matlab, but I
On Wed, 2005-02-23 at 21:14 -0500, rif wrote:
snip
Marc,
This does not do what the matlab code I posted does (the matlab code
also works in the free program octave, if you want to try). The
matlab code moves already plotted data within the window (replots it).
When I first type
On Sat, 13 Dec 2003 [EMAIL PROTECTED] wrote:
On 13-Dec-03 Martin Maechler wrote:
In general, use
== for testing equality of integer numbers (of type integer
or not)
I hope this is not a suggestion to avoid usage like
which(x == max(x))
when x is a vector of
On 15-Dec-03 Thomas Lumley wrote:
One reason that which.max() exists is that we cannot guarantee
which(x==max(x)) to work. It is possible, though rather unlikely, for
there to be no x such that x==max(x). One reason is the unpredictable
use of 10-byte wide floating point registers on Intel
On Mon, 15 Dec 2003 [EMAIL PROTECTED] wrote:
On 15-Dec-03 Thomas Lumley wrote:
One reason that which.max() exists is that we cannot guarantee
which(x==max(x)) to work. It is possible, though rather unlikely, for
there to be no x such that x==max(x). One reason is the unpredictable
use
I hope I am not telling you things you already know. If so, I apologize
in advance.
There are several C-library addons available to try to deal with the
problem that comparisons of floating point numbers can be
unpredictable. I think your example with the greater than sign would
not be a
TL == Thomas Lumley [EMAIL PROTECTED]
on Fri, 12 Dec 2003 14:54:51 -0800 (PST) writes:
TL On Fri, 12 Dec 2003, John Welsh wrote:
for(i in c(1:5)) + { + print(identical(i,1)) + }
[1] FALSE [1] FALSE [1] FALSE [1] FALSE [1] FALSE
Why don't I get:
On 13-Dec-03 Martin Maechler wrote:
In general, use
== for testing equality of integer numbers (of type integer
or not)
I hope this is not a suggestion to avoid usage like
which(x == max(x))
when x is a vector of reals? (i.e. should be OK when you know that
the thing
In that particular case there is also
which.max(x)
---
Date: Sat, 13 Dec 2003 13:31:42 - (GMT)
From: [EMAIL PROTECTED]
To: Martin Maechler [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Basic question on function identical
On 13-Dec-03 Martin Maechler wrote
On Fri, 12 Dec 2003, John Welsh wrote:
for(i in c(1:5))
+ {
+ print(identical(i,1))
+ }
[1] FALSE
[1] FALSE
[1] FALSE
[1] FALSE
[1] FALSE
Why don't I get:
[1] TRUE
[1] FALSE
[1] FALSE
[1] FALSE
[1] FALSE
Because the first element of 1:5 is an integer and 1 is a real number.
One is an integer and the other is not. Try
for (i in 1:5) print( identical( i, as.integer(1) ) )
---
Date: Fri, 12 Dec 2003 14:47:07 -0800
From: John Welsh [EMAIL PROTECTED]
To: '[EMAIL PROTECTED]' [EMAIL PROTECTED]
Subject: [R] Basic question on function identical
for(i in c(1:5
Another neat way is:
with(DF, foo(x, w))
HTH,
Andy
-Original Message-
From: peter leonard [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 08, 2003 4:35 PM
To: [EMAIL PROTECTED]
Subject: [R] Basic question on applying a function to each row of a
dataframe
Hi,
I have
, foo(x, w))
HTH,
Andy
-Original Message-
From: peter leonard [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 08, 2003 4:35 PM
To: [EMAIL PROTECTED]
Subject: [R] Basic question on applying a function to each row of a
dataframe
Hi,
I have a function foo(x,y) and a dataframe, DF
: peter leonard [mailto:[EMAIL PROTECTED]
Sent: Sunday, June 08, 2003 4:35 PM
To: [EMAIL PROTECTED]
Subject: [R] Basic question on applying a function to each row of a
dataframe
Hi,
I have a function foo(x,y) and a dataframe, DF, comprised of
two vectors, x
w, as follows :
x w
1 1 1
2 2 1
3 3 1
4
On Mon, 9 Jun 2003, Sundar Dorai-Raj wrote:
Yes, but very slow for this example when the data.frame gets large
Indeed. However, it works when the function is not already vectorised, and
if the function is already vectorised it is unnecessary.
-thomas
Hi,
I have a function foo(x,y) and a dataframe, DF, comprised of two vectors, x
w, as follows :
x w
1 1 1
2 2 1
3 3 1
4 4 1
etc
I would like to apply the function foo to each 'pair' within DF e.g
foo(1,1), foo(2,1), foo(3,1) etc
I have tried
apply(DF,foo)
apply(DF[,],foo)
How about the following:
DF - data.frame(x=1:4, y=rep(1,4))
foo - function(x, y)x+y
foo(DF$x, DF$y)
[1] 2 3 4 5
hth. spencer graves
peter leonard wrote:
Hi,
I have a function foo(x,y) and a dataframe, DF, comprised of two
vectors, x w, as follows :
x w
1 1 1
2 2 1
3 3 1
4 4 1
etc
Hi,
You need to tell the apply() whether you want to apply the function to
rows (1) or columns (2).
So in your case you may want to try something like:
apply(DF, 1, foo)
On Sun, 8 Jun 2003, peter leonard wrote:
I have a function foo(x,y) and a dataframe, DF, comprised of two vectors, x
Wang [EMAIL PROTECTED]
To: peter leonard [EMAIL PROTECTED]
CC: [EMAIL PROTECTED]
Subject: Re: [R] Basic question on applying a function to each row of a
dataframe Date: Mon, 9 Jun 2003 08:54:02 +1200 (NZST)
Hi,
You need to tell the apply() whether you want to apply the function to
rows (1
This works fine.
Thanks
Peter
From: Spencer Graves [EMAIL PROTECTED]
To: peter leonard [EMAIL PROTECTED]
CC: [EMAIL PROTECTED]
Subject: Re: [R] Basic question on applying a function to each row of
a dataframe
Date: Sun, 08 Jun 2003 13:48:04 -0700
How about the following:
DF - data.frame(x=1:4
Dear R users,
Up to now, I only used precompiled packages. As I am working on vegetation
ecology, I would be interested in using a package not stored by CRAN called
labdsv_0.9-1.tar.gz and developped by Dave Roberts at the National Center
for Ecological Analysis and Synthesis (unfortunately I did
Master of Science (MSc) Student
Department of Statistics
University of Auckland
New Zealand
www.stat.auckland.ac.nz/~kwan022
- Original Message -
From: Archaux Frederic [EMAIL PROTECTED]
To: '[EMAIL PROTECTED]' [EMAIL PROTECTED]
Sent: Tuesday, February 04, 2003 9:46 PM
Subject: [R] basic
On Tue, 2003-02-04 at 10:46, Archaux Frederic wrote:
Up to now, I only used precompiled packages. As I am working on vegetation
ecology, I would be interested in using a package not stored by CRAN called
labdsv_0.9-1.tar.gz and developped by Dave Roberts at the National Center
for Ecological
On Tue, 4 Feb 2003, Ko-Kang Kevin Wang wrote:
From your description I am guessing you're using Windows.
What you may need is to compile this package from source. It is explained
in one of the R manuals (I can't remember which one though).
The file README.packages in the Windows
35 matches
Mail list logo