Re: [R] Creating a Hash from Data.Frame

From: Gundala Viswanath <gundalav_at_gmail.com>
Date: Mon, 16 Jun 2008 11:17:48 +0900

Thanks so much Jim,
I owe you a million!

On Mon, Jun 16, 2008 at 11:03 AM, jim holtman <jholtman_at_gmail.com> wrote:
> here is a way:
>
>> x <- read.table(textConnection("#GDS_ID GENE_NAME GENE_DESCRIPTION GENE_FUNCTION
> + 1007_s_at | DDR1 | discoidin domain receptor tyrosine kinase 1 |
> protein-coding
> + 1053_at | RFC2 | replication factor C (activator 1) 2, 40kDa | protein-coding
> + 117_at | HSPA6 | heat shock 70kDa protein 6 (HSP70B') |
> protein-coding"), sep="|",
> + strip.white=TRUE, quote='') # you need strip.white on the call
>> closeAllConnections()
>> str(x)
> 'data.frame': 3 obs. of 4 variables:
> $ V1: Factor w/ 3 levels "1007_s_at","1053_at",..: 1 2 3
> $ V2: Factor w/ 3 levels "DDR1","HSPA6",..: 1 3 2
> $ V3: Factor w/ 3 levels "discoidin domain receptor tyrosine kinase
> 1",..: 1 3 2
> $ V4: Factor w/ 1 level "protein-coding": 1 1 1
>> x
> V1 V2 V3 V4
> 1 1007_s_at DDR1 discoidin domain receptor tyrosine kinase 1 protein-coding
> 2 1053_at RFC2 replication factor C (activator 1) 2, 40kDa protein-coding
> 3 117_at HSPA6 heat shock 70kDa protein 6 (HSP70B') protein-coding
>> mydata <- character()
>> mydata[as.character(x$V2)] <- as.character(x$V3)
>> mydata["RFC2"] #access the data
> RFC2
> "replication factor C (activator 1) 2, 40kDa"
>>
>
> remember to add the 'strip.white=TRUE' on read.table
>
> On Sun, Jun 15, 2008 at 9:53 PM, Gundala Viswanath <gundalav_at_gmail.com> wrote:
>> Hi,
>>
>> I have the following data frame:
>>
>>> print(mydatframe)
>>
>> __DATAFRAME__
>>
>> V1 V2 V3
>> 1 1007_s_at DDR1 discoidin domain receptor tyrosine kinase 1
>> 2 1053_at RFC2 replication factor C (activator 1) 2, 40kDa
>> 3 117_at HSPA6 heat shock 70kDa protein 6 (HSP70B')
>>
>> __END__
>>

>> Is there a way to create a hash with
>> V2 as Key and V3 as its value?
>>
>> - Gundala Viswanath
>> Jakarta - Indonesia
>>
>> ______________________________________________
>> 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.
>>
>
>
>
> --
> Jim Holtman
> Cincinnati, OH
> +1 513 646 9390
>
> What is the problem you are trying to solve?
>



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. Received on Mon 16 Jun 2008 - 02:23:15 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 16 Jun 2008 - 02:30:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive