[R] python-like dictionary for R

Phil Spector spector at stat.berkeley.edu
Thu Dec 23 03:54:45 CET 2010


Paul -
    You can also use named vectors as something similar to
a python dictionary:

> nvec = c('one'=20,'two'=30,'three'=40)
> nvec['four'] = 50
> nvec['one']
one
  20
> nvec['four']
four
   50

Although the result is named, it can be used as a regular R
value:

> 20 + nvec['three']
three
    60

If the names annoy you (as they seem to annoy many R users),
you can unname the object:

> unname(20 + nvec['three'])
[1] 60

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu



On Wed, 22 Dec 2010, Paul Rigor wrote:

> Hi,
>
> I was wondering if anyone has played around this this package called
> "rdict"? It attempts to implement a hash table in R using skip lists. Just
> came across it while trying to look for simpler text manipulation methods:
>
> http://userprimary.net/posts/2010/05/29/rdict-skip-list-hash-table-for-R/
>
> Cheers,
> Paul
>
> 	[[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