Hi,
I remember I got the same error when I used: setAs("numeric", "NumerictoInteger", function(from) as.integer(from)) ##Using the same dataset datx1 <- read.table(text=a, header=TRUE, stringsAsFactors=FALSE, colClasses=c("character",rep("NumerictoInteger",11))) #Error in methods::as(data[[i]], colClasses[i]) : # no method or default for coercing “character” to “NumerictoInteger” #Changing "numeric" to "character" gives me: setAs("character", "NumerictoInteger", function(from) as.integer(from)) ##though datx1 <- read.table(text=a, header=TRUE, stringsAsFactors=FALSE, colClasses=c("character",rep("NumerictoInteger",11))) str(datx1) 'data.frame': 9 obs. of 12 variables: $ transcript_ID: chr "c101054_g1_i2" "c96583_g1_i2" "c19380_g1_i1" "c102980_g1_i10" ... $ C3 : int 15 0 0 0 0 0 0 0 0 $ C4 : int 231 10 9 0 6 29 0 2 0 $ CRL_2APR10 : int 131 6 0 0 65 2 0 0 0 $ CRL_1_15JUL11: int 218 8 1 0 0 0 54 1 0 $ CRL_2_15JUL11: int 16 0 0 0 0 0 0 0 0 $ C1 : int 0 0 0 0 0 0 1 0 0 $ CRL_6OCT11c : int 587 29 0 0 40 29 0 0 0 $ CRL_3DEC11 : int 0 0 0 0 0 0 0 0 0 $ CRL_13DEC11b : int 624 90 0 0 55 338 0 0 0 $ LRV_A : int 10 0 0 0 0 0 0 0 0 $ LRV_B : int 6 0 0 0 0 0 0 0 1 A.K. On Wednesday, May 14, 2014 2:46 PM, Alicia R. Pérez-Porro <alicia.r.perezpo...@gmail.com> wrote: Sorry, I am pretty new using R. Here is my code to read the table: library("DESeq2") setwd("~/Dropbox/TESIS/DGEA_2.0/Chapter_4_thesis/DE_analysis/DESeq2") matrix = read.table (file.choose(), header=TRUE, row.names=1) CeleDesign <- data.frame( row.names = colnames(matrix), condition = factor(c("SP", "SP", "EB", "EB"))) dds <- DESeqDataSetFromMatrix(countData = matrix, colData = CeleDesign, design = ~ condition) By typing: > setwd("~/Dropbox/TESIS/DGEA_2.0/Chapter_4_thesis/DE_analysis/DESeq2") > setClass("NumerictoInteger") > setAs("numeric", "NumerictoInteger", function(from) as.integer(from)) > matrix <- read.table(file.choose(), header=TRUE, , row.names=1, > stringsAsFactors=FALSE, + colClasses=c("character",rep("NumerictoInteger",11))) Error in methods::as(data[[i]], colClasses[i]) : no method or default for coercing “character” to “NumerictoInteger” My table has 12 columns and 138519 rows. Any extra suggestion? Thanks, 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 On Mon, May 12, 2014 at 9:57 PM, arun <smartpink...@yahoo.com> wrote: 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 <dcarl...@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-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On >Behalf Of Alicia R. Pérez-Porro >Sent: Monday, May 12, 2014 10:38 AM >To: r-help@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@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. > ______________________________________________ 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.