Help! What does this R command mean?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Help! What does this R command mean?

LosemindL
Hi all,

R is so difficult. I am so desperate.

What does the ":" mean in the following statement?

What does the "[, -1]" mean?

>
> # Leaps takes a design matrix as argument: throw away the intercept
> # column or leaps will complain
>
> X <- model.matrix(lm(V ~ I + D + W +G:I + P + N, election.table))[,-1]

Thanks a lot!

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Help! What does this R command mean?

Simon Blomberg
RTFM! Especially the Introduction to R tutorial. Type help.start() at
the prompt. It should open your web browser. Choose "Introduction to R".
Only then will you attain enlightenment.

Simon.

Michael wrote:

> Hi all,
>
> R is so difficult. I am so desperate.
>
> What does the ":" mean in the following statement?
>
> What does the "[, -1]" mean?
>
>  
>> # Leaps takes a design matrix as argument: throw away the intercept
>> # column or leaps will complain
>>
>> X <- model.matrix(lm(V ~ I + D + W +G:I + P + N, election.table))[,-1]
>>    
>
> Thanks a lot!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>  


--
Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat.
Centre for Resource and Environmental Studies
The Australian National University
Canberra ACT 0200
Australia
T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au
F: +61 2 6125 0757
CRICOS Provider # 00120C

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Help! What does this R command mean?

Gabor Grothendieck
In reply to this post by LosemindL
?":"
?"["

Also try
?"?"

Also
1. read the "An Introduction to R" manual.  On R Home page click on
Manuals under Documentation in the left hand column.
2. go to:
   http://cran.r-project.org/other-docs.html
and read your choice of documents.
3. print out this reference card and keep it handy:
  http://www.rpad.org/Rpad/R-refcard.pdf

On 1/29/06, Michael <[hidden email]> wrote:

> Hi all,
>
> R is so difficult. I am so desperate.
>
> What does the ":" mean in the following statement?
>
> What does the "[, -1]" mean?
>
> >
> > # Leaps takes a design matrix as argument: throw away the intercept
> > # column or leaps will complain
> >
> > X <- model.matrix(lm(V ~ I + D + W +G:I + P + N, election.table))[,-1]
>
> Thanks a lot!
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Help! What does this R command mean?

LosemindL
After reading your pointers, I still don't understand that particular usage
of ":":

btw, the data after read.table():

   Year      V  I  D W       G      P  N
1  1916 0.5168  1  1 0   2.229  4.252  3
2  1920 0.3612  1  0 1 -11.463 16.535  5
3  1924 0.4176 -1 -1 0  -3.872  5.161 10

On 1/29/06, Gabor Grothendieck <[hidden email]> wrote:

>
> ?":"
> ?"["
>
> Also try
> ?"?"
>
> Also
> 1. read the "An Introduction to R" manual.  On R Home page click on
> Manuals under Documentation in the left hand column.
> 2. go to:
>    http://cran.r-project.org/other-docs.html
> and read your choice of documents.
> 3. print out this reference card and keep it handy:
>   http://www.rpad.org/Rpad/R-refcard.pdf
>
> On 1/29/06, Michael <[hidden email]> wrote:
> > Hi all,
> >
> > R is so difficult. I am so desperate.
> >
> > What does the ":" mean in the following statement?
> >
> > What does the "[, -1]" mean?
> >
> > >
> > > # Leaps takes a design matrix as argument: throw away the intercept
> > > # column or leaps will complain
> > >
> > > X <- model.matrix(lm(V ~ I + D + W +G:I + P + N, election.table))[,-1]
> >
> > Thanks a lot!
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> >
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Help! What does this R command mean?

Simon Blomberg-2
?formula

Michael wrote:

> After reading your pointers, I still don't understand that particular usage
> of ":":
>
> btw, the data after read.table():
>
>    Year      V  I  D W       G      P  N
> 1  1916 0.5168  1  1 0   2.229  4.252  3
> 2  1920 0.3612  1  0 1 -11.463 16.535  5
> 3  1924 0.4176 -1 -1 0  -3.872  5.161 10
>
> On 1/29/06, Gabor Grothendieck <[hidden email]> wrote:
>  
>> ?":"
>> ?"["
>>
>> Also try
>> ?"?"
>>
>> Also
>> 1. read the "An Introduction to R" manual.  On R Home page click on
>> Manuals under Documentation in the left hand column.
>> 2. go to:
>>    http://cran.r-project.org/other-docs.html
>> and read your choice of documents.
>> 3. print out this reference card and keep it handy:
>>   http://www.rpad.org/Rpad/R-refcard.pdf
>>
>> On 1/29/06, Michael <[hidden email]> wrote:
>>    
>>> Hi all,
>>>
>>> R is so difficult. I am so desperate.
>>>
>>> What does the ":" mean in the following statement?
>>>
>>> What does the "[, -1]" mean?
>>>
>>>      
>>>> # Leaps takes a design matrix as argument: throw away the intercept
>>>> # column or leaps will complain
>>>>
>>>> X <- model.matrix(lm(V ~ I + D + W +G:I + P + N, election.table))[,-1]
>>>>        
>>> Thanks a lot!
>>>
>>>        [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide!
>>>      
>> http://www.R-project.org/posting-guide.html
>>    
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>  


--
Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat.
Centre for Resource and Environmental Studies
The Australian National University
Canberra ACT 0200
Australia
T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au
F: +61 2 6125 0757
CRICOS Provider # 00120C

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Help! What does this R command mean?

Ionut Florescu
In reply to this post by LosemindL
a:b means - all the element in the vector from a to b
a[,-1] means for the matrix a keep all the rows but not the last or
first -can't remember column.
When in doubt do what I do make a small matrix and apply the command see
what it does.
After this:
 > a=matrix(c(1:9),3,3)
 > a[,-1]
     [,1] [,2]
[1,]    4    7
[2,]    5    8
[3,]    6    9

you see that -1 eliminates the first column.
I found the R manual useless myself.
The only thing useful is the search function in the html help. That has
examples.

Ionut Florescu

Michael wrote:

> Hi all,
>
> R is so difficult. I am so desperate.
>
> What does the ":" mean in the following statement?
>
> What does the "[, -1]" mean?
>
>  
>> # Leaps takes a design matrix as argument: throw away the intercept
>> # column or leaps will complain
>>
>> X <- model.matrix(lm(V ~ I + D + W +G:I + P + N, election.table))[,-1]
>>    
>
> Thanks a lot!
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: Help! What does this R command mean?

Liaw, Andy
In reply to this post by LosemindL
":" in a formula is not the same as ":" otherwise!

Andy

From: Ionut Florescu

>
> a:b means - all the element in the vector from a to b
> a[,-1] means for the matrix a keep all the rows but not the last or
> first -can't remember column.
> When in doubt do what I do make a small matrix and apply the
> command see
> what it does.
> After this:
>  > a=matrix(c(1:9),3,3)
>  > a[,-1]
>      [,1] [,2]
> [1,]    4    7
> [2,]    5    8
> [3,]    6    9
>
> you see that -1 eliminates the first column.
> I found the R manual useless myself.
> The only thing useful is the search function in the html
> help. That has
> examples.
>
> Ionut Florescu
>
> Michael wrote:
> > Hi all,
> >
> > R is so difficult. I am so desperate.
> >
> > What does the ":" mean in the following statement?
> >
> > What does the "[, -1]" mean?
> >
> >  
> >> # Leaps takes a design matrix as argument: throw away the intercept
> >> # column or leaps will complain
> >>
> >> X <- model.matrix(lm(V ~ I + D + W +G:I + P + N,
> election.table))[,-1]
> >>    
> >
> > Thanks a lot!
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > [hidden email] mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
> >
> >
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html