Hi all, While dat['a1',] and dat['a10',] produce the same results in the following example, I'd like dat['a1',] to return NAs. dat <- data.frame(x1 = paste(letters[1:5],10, sep=''), x2=rnorm(5)) rownames(dat) <- dat$x1 dat['a1',] dat['a10',]> sessionInfo()R version 2.7.2 (2008-08-25) i386-pc-mingw32 locale: LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MON ETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] lattice_0.17-13 loaded via a namespace (and not attached): [1] grid_2.7.2>Regards, Xianming DISCLAIMER:\ For details of our e-mail disclaimer, pleas...{{dropped:15}}
try this: dat <- data.frame(x1 = paste(letters[1:5],10, sep=''), x2=rnorm(5)) row.names(dat) <- dat$x1 dat['a1' %in% row.names(dat), ] dat['a10' %in% row.names(dat), ] I hope it helps. Best, Dimitris> Hi all, > > While dat['a1',] and dat['a10',] produce the same results in the > following example, I'd like dat['a1',] to return NAs. > > dat <- data.frame(x1 = paste(letters[1:5],10, sep=''), x2=rnorm(5)) > rownames(dat) <- dat$x1 > dat['a1',] > dat['a10',] > >> sessionInfo() > R version 2.7.2 (2008-08-25) > i386-pc-mingw32 > > locale: > LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MON > ETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > > other attached packages: > [1] lattice_0.17-13 > > loaded via a namespace (and not attached): > [1] grid_2.7.2 >> > > Regards, > Xianming > > > > DISCLAIMER:\ For details of our e-mail disclaimer, pleas...{{dropped:15}} > > ______________________________________________ > 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. >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043399 Fax: +31/(0)10/7044657
As suggested in ?"[.data.frame", try: dat[match('a1', rownames(dat)),] Haris Skiadas Department of Mathematics and Computer Science Hanover College On Sep 9, 2008, at 2:41 AM, Xianming Wei wrote:> Hi all, > > While dat['a1',] and dat['a10',] produce the same results in the > following example, I'd like dat['a1',] to return NAs. > > dat <- data.frame(x1 = paste(letters[1:5],10, sep=''), x2=rnorm(5)) > rownames(dat) <- dat$x1 > dat['a1',] > dat['a10',] > >> sessionInfo() > R version 2.7.2 (2008-08-25) > i386-pc-mingw32 > > locale: > LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia. > 1252;LC_MON > ETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia. > 1252 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > > other attached packages: > [1] lattice_0.17-13 > > loaded via a namespace (and not attached): > [1] grid_2.7.2 >> > > Regards, > Xianming >