I think the help file for apply() warns you that if you give it a data.frame, the data.frame will be converted to a matrix, with X <- as.matrix(X), before FUN is called on its rows or columns. Look at what as.matrix does to your data: since there is a non-numeric column it produces a character matrix and since in the second example some numbers have 2 digits, the other numbers have a leading space.
> as.matrix(a[1:2,]) row column assay plate 1 "B" "2" "Assay1" "1" 2 "C" "2" "Assay1" "1" > as.matrix(a[1:3,]) row column assay plate 1 "B" " 2" "Assay1" "1" 2 "C" " 2" "Assay1" "1" 3 "B" "10" "Assay1" "1" I avoid using apply() on data.frames. Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Aug 8, 2017 at 11:39 AM, Ramiro Barrantes < ram...@precisionbioassay.com> wrote: > Hello, > > In my code I found something that looks like an anomaly, I found a > reproducible example in which I am just trying to compare each row in a > data frame against the first row: > > a<-data.frame(row=c("B","C","B"),column=c(2,2,10),assay=c(" > Assay1","Assay1","Assay1"),plate=c(1,1,1),stringsAsFactors=FALSE) > apply(a[1:2,],1,function(x) { all(x==a[1,]) }) > apply(a[1:3,],1,function(x) { all(x==a[1,]) }) > > > 1 2 > TRUE FALSE > > 1 2 3 > FALSE FALSE FALSE > > > > The second result is not right, it should be TRUE FALSE FALSE > > Am I doing something wrong or is this a bug? With other inputs it seems > to work ok > > Here is my sessionInfo() > > sessionInfo() > R version 3.2.5 (2016-04-14) > Platform: x86_64-redhat-linux-gnu (64-bit) > Running under: CentOS release 6.9 (Final) > > locale: > [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C > [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 > [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 > [7] LC_PAPER=en_US.UTF-8 LC_NAME=C > [9] LC_ADDRESS=C LC_TELEPHONE=C > [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > > > Thank you, > Ramiro > > > > Ramiro Barrantes Ph.D. > Precision Bioassay, Inc. > 431 Pine St., Suite 110 > Burlington, VT 05401 > 802 865 0155 > 802 861 2365 FAX > www.precisionbioassay.com<https://west.exch023.serverdata. > net/owa/redir.aspx?SURL=wN3KzpoKXAcetH7sTOTnSyfg- > iAXFIinpPUtRcduCFCtkgZrUSDTCGgAdAB0AHAAOgAvAC8AdwB3AHcALgBwA > HIAZQBjAGkAcwBpAG8AbgBiAGkAbwBhAHMAcwBhAHkALgBjAG8AbQA.&URL= > http%3a%2f%2fwww.precisionbioassay.com> > ram...@precisionbioassay.com > > CONFIDENTIALITY NOTICE: This email, including any attach...{{dropped:9}} > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.