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="+")))
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 environ
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 regres
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. somethin
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 95
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 20
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:
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
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
On Wed, 2005-02-23 at 21:14 -0500, rif wrote:
> 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 plot(1:1
> 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 no
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 ad
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
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 sour
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 unpredictab
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 In
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
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-
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 th
> "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
>
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 "id
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 an
> 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
John Welsh
Associate Professor
Sidney Kimmel Cancer Center
10835 Altman Row
San Diego, CA 92121
(858) 450-5990 ex.282
[EMAIL
This works fine. Thanks everybody for all your help,
Peter
From: Thomas Lumley <[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 06:47:20 -0700 (
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
_
foo(DF)
[1] 2 3 4 5
"Liaw, Andy" <[EMAIL PROTECTED]> wrote:
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
On Sun, 8 Jun 2003, 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
>
>
> I would like to apply the function foo to each 'pair' within DF e.g
> foo(1,1), foo(2,1)
"Liaw, Andy" <[EMAIL PROTECTED]> wrote:
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
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
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:
> D
Regards
Peter
From: Ko-Kang Kevin 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() wh
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
>
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
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)
apply(DF
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 distrib
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 Ecologic
Archaux Frederic wrote:
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 Synthe
IL PROTECTED]>
Sent: Tuesday, February 04, 2003 9:46 PM
Subject: [R] basic question
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 Dav
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
39 matches
Mail list logo