[R] What does [[1]] mean?

2012-01-26 Thread Ajay Askoolum
I know that [] is used for indexing.
I know that [[]] is used for reference to a property of a COM object.

I cannot find any explanation of what [[1]] does or, more pertinently, where it 
should be used.

Thank you.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] What does [[1]] mean?

2012-01-26 Thread Greg Snow
Have you read ?[[ ?

The short answer is that you can use both [] and [[]] on lists, the [] 
construct will return a subset of  the list (which will be a list) while [[]] 
will return a single element of the list (which could be a list or a vector or 
whatever that element may be):  compare:

 tmp - list( a=1, b=letters )
 tmp[1]
$a
[1] 1

 tmp[1] + 1
Error in tmp[1] + 1 : non-numeric argument to binary operator
 tmp[[1]]
[1] 1
 tmp[[1]] + 1
[1] 2

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of Ajay Askoolum
 Sent: Thursday, January 26, 2012 11:27 AM
 To: R General Forum
 Subject: [R] What does [[1]] mean?
 
 I know that [] is used for indexing.
 I know that [[]] is used for reference to a property of a COM object.
 
 I cannot find any explanation of what [[1]] does or, more pertinently,
 where it should be used.
 
 Thank you.
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-
 guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] What does [[1]] mean?

2012-01-26 Thread Patrick Burns

Here is a page that should help:

http://www.burns-stat.com/pages/Tutor/more_R_subscript.html

Also Circle 8.1.54 of 'The R Inferno'
http://www.burns-stat.com/pages/Tutor/R_inferno.pdf


On 26/01/2012 18:27, Ajay Askoolum wrote:

I know that [] is used for indexing.
I know that [[]] is used for reference to a property of a COM object.

I cannot find any explanation of what [[1]] does or, more pertinently, where it 
should be used.

Thank you.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



--
Patrick Burns
pbu...@pburns.seanet.com
twitter: @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of 'Some hints for the R beginner'
and 'The R Inferno')

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.