[R] What does [[1]] mean?
Greg Snow
Greg.Snow at imail.org
Thu Jan 26 19:55:08 CET 2012
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.snow at imail.org
801.408.8111
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at 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 at 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.
More information about the R-help
mailing list