[R] Convert to integers all entries of a table (for DESeq2)

arun smartpink111 at yahoo.com
Tue May 13 03:57:44 CEST 2014


Hi,

You may also try using 'colClasses' while reading the data.
setClass("NumerictoInteger")
setAs("numeric", "NumerictoInteger", function(from) as.integer(from)) 
datx1 <- read.table(text=a, header=TRUE, stringsAsFactors=FALSE, colClasses=c("character",rep("NumerictoInteger",11)))

##David's result
  dati <- data.frame(transcript_ID=datx$transcript_ID, sapply(datx[,-1], as.integer),
         stringsAsFactors=FALSE)

 all.equal(dati, datx1)
#[1] TRUE

A.K.


On Monday, May 12, 2014 4:35 PM, David L Carlson <dcarlson at tamu.edu> wrote:
a <- "transcript_ID C3 C4 CRL_2APR10 CRL_1_15JUL11 CRL_2_15JUL11 C1 CRL_6OCT11c CRL_3DEC11  CRL_13DEC11b LRV_A LRV_B
c101054_g1_i2 15.53 231.47 131.86 218.69 16.70 0.00 587.79 0.00 624.32 10.00 6.00
c96583_g1_i2 0.00 10.60 6.30 8.87 0.00 0.00 29.00 0.00 90.94 0.00 0.00
c19380_g1_i1 0.00 9.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
c102980_g1_i10 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
c91905_g1_i3 0.00 6.66 65.11 0.00 0.00 0.00 40.92 0.00 55.37 0.00 0.00
c108262_g1_i3 0.00 29.65 2.44 0.00 0.00 0.00 29.33 0.00 338.89 0.00 0.00
c27948_g1_i1 0.00 0.00 0.00 54.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00
c14898_g1_i1 0.00 2.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
c105146_g1_i2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00"
datx <- read.table(text=a, header=TRUE, stringsAsFactors=FALSE)

dati <- data.frame(datx$transcript_ID, sapply(datx[,-1], as.integer),
        stringsAsFactors=FALSE)

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Alicia R. Pérez-Porro
Sent: Monday, May 12, 2014 10:38 AM
To: r-help at r-project.org
Subject: [R] Convert to integers all entries of a table (for DESeq2)

Dear R users,

I have a .txt table that looks like:

transcript_ID C3        C4      CRL_2APR10      CRL_1_15JUL11
CRL_2_15JUL11   C1      CRL_6OCT11c     CRL_3DEC11      CRL_13DEC11b
LRV_A LRV_B
c101054_g1_i2 15.53 231.47 131.86 218.69 16.70 0.00 587.79 0.00 624.32 10.00
6.00
c96583_g1_i2 0.00 10.60 6.30 8.87 0.00 0.00 29.00 0.00 90.94 0.00 0.00
c19380_g1_i1 0.00 9.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
c102980_g1_i10 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
c91905_g1_i3 0.00 6.66 65.11 0.00 0.00 0.00 40.92 0.00 55.37 0.00 0.00
c108262_g1_i3 0.00 29.65 2.44 0.00 0.00 0.00 29.33 0.00 338.89 0.00 0.00
c27948_g1_i1 0.00 0.00 0.00 54.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00
c14898_g1_i1 0.00 2.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
c105146_g1_i2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00

I need to convert all the numeric entries into integers to be able to use
DESeq2, e.g.:

C3 C4 CRL2APR10 CRL_1_15JUL11 CRL_2_15JUL11 C1 CRL_6OCT11c CRL3DEC11
CRL13DEC11b LRV_A LRV_B
c101054_g1_i2 15 231 131 218 16 0 587 0 624 10 6
c96583_g1_i2 0 10 6 8 0 0 29 0 90 0 0
c19380_g1_i1 0 9 0 1 0 0 0 0 0 0 0
c102980_g1_i10 0 0 0 0 0 0 0 0 0 0 0
c91905_g1_i3 0 6 65 0 0 0 40 0 55 0 0
c108262_g1_i3 0 29 2 0 0 0 29 0 338 0 0
c27948_g1_i1 0 0 0 54 0 1 0 0 0 0 0
c14898_g1_i1 0 2 0 1 0 0 0 0 0 0 0
c105146_g1_i2 0 0 0 0 0 0 0 0 0 0 1

​Any help will be welcome.
Thanks in advance,

Alicia​

--
Alicia R. Pérez-Porro
PhD candidate

Giribet lab
Department of Organismic and Evolutionary Biology
MCZ labs
Harvard University
26 Oxford St, Cambridge MA 02138
phone: +1 617-496-5308
fax: +1 617-495-5667
www.oeb.harvard.edu/faculty/giribet/

Department of Marine Ecology
Center for Advanced Studies of Blanes (CEAB-CSIC)
C/Accés Cala St. Francesc 14
17300 Blanes, Girona, SPAIN
phone: +34 972 336 101
fax: +34 972 337 806
www.ceab.csic.es

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



More information about the R-help mailing list