[R] only "T" becomes logical colum with read.table

Henrique Dallazuanna wwwhsd at gmail.com
Fri Jul 18 15:06:25 CEST 2008


Try this:

x <- read.table('example.txt', colClasses = rep("character", 7))

On Fri, Jul 18, 2008 at 9:53 AM, Luis F <respostas17 at gmail.com> wrote:
> Hello,
>
> I am a biologist and I am dealing with files composed of columns with T or A
> or C or G (example below)
>
> Sometimes a column is composed of only "T"
> and in that case, the columns becomes a logical column TRUE  (example below)
>
> I know that the argument "as.is" controls the turns off turning a column
> into a factor, instead becoming a character
> Is there something similar for Iogical? (I could not find it)
>
> I can solve this problem by doing something like:
> #
> FUN.changeLogi <- function(df){
>  if(identical(all.equal(all(df), T), T)) df <- 'T'
>  return(df)
> }
> xx <- do.call('cbind', lapply(xx, FUN.changeLogi))
>
> but it seems very cumbersome…
>
> Thanks,
> Tiago Magalhães
>
> produce a text file example.txt
>
> A C A T C G F
> A A C T C G F
> A C A T C G F
> A G A T C G F
> T A C T C G F
>
> xx <- read.table('example.txt')
> str(xx)
> xx <- read.table('~/Desktop/temp.txt')
>  $ V1: chr  "A" "A" "A" "A" ...
>  $ V2: chr  "C" "A" "C" "G" ...
>  $ V3: chr  "A" "C" "A" "A" ...
>  $ V4: logi  TRUE TRUE TRUE TRUE TRUE
>  $ V5: chr  "C" "C" "C" "C" ...
>  $ V6: chr  "G" "G" "G" "G" ...
>  $ V7: logi  FALSE FALSE FALSE FALSE FALSE
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list