I would like to address the rows of a data frame by a string name, and the table will be built sequentially. I want to do something like
> mytab <- data.frame(city=c("tokyo","delhi","lima"),price=c(9,8,7),row.names=1)
> mytab
price
tokyo 9
delhi 8
lima 7
> # I can add a new row
> mytab["london",] = 8.5
I now need to check whether a row name already exists.
> mytab["ny",]
[1] NA
Is there anything better that I can do other than
> if (is.na(mytab["ny",])) { mytab["ny",]=9;}
since a NA may possibly arise otherwise?
Something like this
might do the trick.