On Mon, Sep 26, 2011 at 4:16 PM, Khanvilkar, Shashank <skhan...@qualcomm.com> wrote: > Sending it again, with correct subject line. > > > Hello All, > Thanks in advance for all help, > > I am trying to read a two column csv file in R, which looks like: > X,1 > Y,2 > Z,3 > > I am using R commands: > tmp = read.csv("test.csv", colClasses=c("character", "character")) > > How can make this into a hash table, so that I can access, tmp["X"] and it > will return me "1"? >
Try this: Lines <- "letters,numbers X,1 Y,2 Z,3" cat(Lines, "\n", file = "data.txt") DF <- read.csv("data.txt") v <- setNames(DF[,2], DF[,1]) so: > v[["Y"]] [1] 2 -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ 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.