Q:

How to get dictionary functionality from a data.frame in R

R doesn't seem to have a dictionary structure. Let's say I have a data.frame of people who have unique first names (keys):
people = data.frame(c("Bob", "Jones"), c("Sally", "Smith"));
names(people) = c("Firstname", "Surname");

I want to know what Sally's Surname is, only knowing her Firstname.
I could write some ugly code that traverses people$Firstname, keeping track of an index, and then fetching people$Lastname at that index once I find a match, but this probably isn't the right way.
What's the "R way" to do this?

A:

I don't think your data frame is crafted the way you think it is. Using this one, it's pretty simple:
people <- data.frame(Firstname=c("Bob", "Sally"),
                     Surname=c("Jones", "Smith"), 
                     stringsAsFactors=FALSE)

people[people$Firstname=="Sally",]$Surname
## [1] Smith

You could also craft it as a list:
ppl <- list("Bob"=list(Surname="Jones"),
            "Sally"=list(Surname="Smith"))

ppl[["Bob"]]
## $Surname
## [1] "Jones"

