[R] basic question re lm()

2006-08-10 Thread r user
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.

Re: [R] basic question re lm()

2006-08-10 Thread Gabor Grothendieck
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

Re: [R] basic question re lm() [Broadcast]

2006-08-10 Thread Liaw, Andy
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

Re: [R] basic question re lm()

2006-08-10 Thread Simon Blomberg
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=+))) }

[R] basic question

2005-04-21 Thread jose silva
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

Re: [R] basic question

2005-04-21 Thread Christoph Lehmann
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:

Re: [R] basic question

2005-04-21 Thread Marc Schwartz
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

Re: [R] basic question

2005-04-21 Thread Marc Schwartz
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

Re: [R] basic question about changing limits on generated plots

2005-02-24 Thread Jan T. Kim
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),

[R] basic question about changing limits on generated plots

2005-02-23 Thread rif
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

Re: [R] basic question about changing limits on generated plots

2005-02-23 Thread Marc Schwartz
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

Re: [R] basic question about changing limits on generated plots

2005-02-23 Thread rif
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

Re: [R] basic question about changing limits on generated plots

2005-02-23 Thread Marc Schwartz
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

Re: [R] Basic question on function identical

2003-12-15 Thread Thomas Lumley
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

Re: [R] Basic question on function identical

2003-12-15 Thread Ted Harding
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

Re: [R] Basic question on function identical

2003-12-15 Thread Thomas Lumley
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

Re: [R] Basic question on function identical

2003-12-15 Thread Paul Johnson
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

Re: [R] Basic question on function identical

2003-12-13 Thread Martin Maechler
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:

Re: [R] Basic question on function identical

2003-12-13 Thread Ted Harding
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

Re: [R] Basic question on function

2003-12-13 Thread Gabor Grothendieck
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

Re: [R] Basic question on function identical

2003-12-12 Thread Thomas Lumley
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.

RE: [R] Basic question on function

2003-12-12 Thread Gabor Grothendieck
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

RE: [R] Basic question on applying a function to each row of ada taframe

2003-06-09 Thread Liaw, Andy
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

RE: [R] Basic question on applying a function to each row of a dataframe

2003-06-09 Thread Ramzi Feghali
, 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

Re: [R] Basic question on applying a function to each row of a dataframe

2003-06-09 Thread Sundar Dorai-Raj
: 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

Re: [R] Basic question on applying a function to each row of a dataframe

2003-06-09 Thread Thomas Lumley
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

[R] Basic question on applying a function to each row of adataframe

2003-06-08 Thread peter leonard
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)

Re: [R] Basic question on applying a function to each row ofa dataframe

2003-06-08 Thread Spencer Graves
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

Re: [R] Basic question on applying a function to each row of adataframe

2003-06-08 Thread Ko-Kang Kevin Wang
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

Re: [R] Basic question on applying a function to each row of adataframe

2003-06-08 Thread peter leonard
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

Re: [R] Basic question on applying a function to each row of adataframe

2003-06-08 Thread peter leonard
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

[R] basic question

2003-02-04 Thread Archaux Frederic
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

Re: [R] basic question

2003-02-04 Thread Ko-Kang Kevin Wang
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

Re: [R] basic question

2003-02-04 Thread Jari Oksanen
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

Re: [R] basic question

2003-02-04 Thread ripley
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