[R] read.table - replaces 'T' with 'TRUE'
Duncan Murdoch
murdoch.duncan at gmail.com
Mon Jan 26 23:10:50 CET 2015
On 26/01/2015 4:52 PM, Brian Smith wrote:
> Hi,
>
> I had a table with 'T's in it. When I try to read the table, it replaces
> all the 'T's with TRUE. Is there a way that I can retain the Ts?
That only happens for columns which are all T. (You only have one row,
so every T gets converted.) The reason is that you didn't tell
read.table what type to expect, so it tried to work it out from the values.
If you know that all values are character, say so, and things will be fine:
read.table(<other args as before>, colClasses = "character")
(You might want "factor" instead of character.)
Duncan Murdoch
>
> thanks!
>
>
> Sample table (test.txt):
>
> xx1 xx2 0 0 2 2 A A G G A G A A C C G G G G G G A G A A A G A G A A G G A A
> A G G G A G A G G G A G A G G G G G A G G G G G A A C C G G A C A G G G A G
> G G A C C C A G A G G G G G G G A A A C A G G G G G G G G G A A G G G G T T
> G G A A G G G G G G A A G G G G G G G G A G T T A G A G G G A G C G G G G G
> G G A G A G A C G G G G A G A G G G G G G G G G G G C C G G G G A A A G A G
> A G G G A G A A A G A G G G G G A A A G G G G G G G A A G G G G G G G G G G
> G G A G A G G G G G A A G G G G G G G G G G A A G G G G A G G G A A C C G G
> C C C G G G A A G G G G G G C C A A G G G G G G A G G G C C G G A A A A G G
> A A G G A G G G A A A G A A G G G G C C G G G G A A G G A A A G G G G G G G
> G G A A A G G G C C G G G G A A G G G G G G G G A A G G G G G G G G G G A A
> G G C C A A A G A A A A A A A G G G G G A C G G G G A A A G A A T T A G A A
> T T A A A A G G G G C C A G G G A G G G G G C C A C A G A G A G A G A G A G
> C C A G G G A G A G A A A A A G A G A A A G A G A C A C A C C C A G A G G G
> G G A G A G C C G G A G A G A G G G G G A G A G A G A G A G A G G G G G A G
> A A A G G G G G A G G G G G G G A A A A G G G G A A A C A G G G A G C C A G
> A G G G G G A T A G A G A C A A A G C C A G G G G G A G A A G G A G C C G G
> A A G G C C C C G G G G T T C C
>
>
>> r1 <- read.table(paste(exdir,'test.txt',sep=''),na.strings="",fill=T)
>> r1
>
>> r1
> V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20
> V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32
> 1 xx1 xx2 0 0 2 2 A A G G A G A A C C G G G
> G G G A G A A A G A G A A
> V33 V34 V35 V36 V37 V38 V39 V40 V41 V42 V43 V44 V45 V46 V47 V48 V49 V50
> V51 V52 V53 V54 V55 V56 V57 V58 V59 V60 V61 V62
> 1 G G A A A G G G A G A G G G A G A G
> G G G G A G G G G G A A
> V63 V64 V65 V66 V67 V68 V69 V70 V71 V72 V73 V74 V75 V76 V77 V78 V79 V80
> V81 V82 V83 V84 V85 V86 V87 V88 V89 V90 V91 V92
> 1 C C G G A C A G G G A G G G A C C C
> A G A G G G G G G G A A
> V93 V94 V95 V96 V97 V98 V99 V100 V101 V102 V103 V104 V105 V106 V107 V108
> V109 V110 V111 V112 V113 V114 V115 V116 V117
> 1 A C A G G G G G G G G G A A G
> G G G TRUE TRUE G G A A G
> V118 V119 V120 V121 V122 V123 V124 V125 V126 V127 V128 V129 V130 V131
> V132 V133 V134 V135 V136 V137 V138 V139 V140 V141
> 1 G G G G G A A G G G G G G G
> G A G TRUE TRUE
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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