[R] Converting Factor to Vector

Gundala Viswanath gundalav at gmail.com
Tue Jan 13 06:50:01 CET 2009


Hi Bill,

However with as.character it fail show the actual strings.

It gives this:

> new_repo <- as.character(repo)
> str(new_repo)
 chr "1:32267"
> print(new_repo)
[1] "1:32267"

Instead of

>> str(new_repo)
> chr [1:100] "AAA" "AAT" "AAC" "AAG" "ATA" "ATT"...
>
>> print(new_repo)
> [1] "AAA" "AAT" "AAC" "AAG" "ATA" "ATT"...


- Gundala Viswanath
Jakarta - Indonesia



On Tue, Jan 13, 2009 at 2:40 PM,  <Bill.Venables at csiro.au> wrote:
> as.character()
>
>
> Bill Venables
> http://www.cmis.csiro.au/bill.venables/
>
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Gundala Viswanath
> Sent: Tuesday, 13 January 2009 3:25 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Converting Factor to Vector
>
> Hi all,
>
> How can I convert factor like this:
>
>> str(repo)
> 'data.frame':   1000 obs. of  1 variable:
>  $ AAA: Factor w/ 1000 levels "AAT","AAC",..: 1 2 3 4 5 6 7 8 9 10 ...
>> print(repo)
> AAA
> 1  AAA
> 2  AAT
> 3  AAC
> ...
>
> into to simple vector
>
>> str(new_repo)
> chr [1:100] "AAA" "AAT" "AAC" "AAG" "ATA" "ATT"...
>
>> print(new_repo)
> [1] "AAA" "AAT" "AAC" "AAG" "ATA" "ATT"...
>
>
> I tried as.vector(), but it remains the same factor.
>
> - 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.
>




More information about the R-help mailing list