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@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.

Reply via email to