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

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Fri, 18 Jul 2008 10:06:25 -0300

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

______________________________________________
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 Fri 18 Jul 2008 - 13:09:41 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 Fri 18 Jul 2008 - 13:31:57 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