cherrera at cs.nmsu.edu
2008-Aug-13 03:25 UTC
[Rd] Column name disappears when indexing a single column (PR#12532)
Good Day, I can understand that after indexing a single column in a matrix, R will return a vector instead of the single column. However, during the conversion to a vector, the column name is lost. I was wondering if it would be better to have R return a single column matrix (retaining the column name), instead of automatically converting to a vector. Users could use as.vector() to convert afterwards. Thanks, CMHJ <<insert bug report here>> --please do not edit the information below-- Version: platform = x86_64-unknown-linux-gnu arch = x86_64 os = linux-gnu system = x86_64, linux-gnu status = major = 2 minor = 7.1 year = 2008 month = 06 day = 23 svn rev = 45970 language = R version.string = R version 2.7.1 (2008-06-23) Locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C Search Path: .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base
Prof Brian Ripley
2008-Aug-13 06:09 UTC
[Rd] (PR#12532) Column name disappears when indexing a single column
On Wed, 13 Aug 2008, cherrera at cs.nmsu.edu wrote:> Good Day,> I can understand that after indexing a single column in a matrix, R > will return a vector instead of the single column. However, during the > conversion to a vector, the column name is lost.> I was wondering if it would be better to have R return a single column > matrix (retaining the column name), instead of automatically converting > to a vector. Users could use as.vector() to convert afterwards.This is NOT a bug. You give no example, and your subject line is incorrect. You probably mean 'extracting a single column from a matrix' and no name 'disappears' -- the matrix still has its column names. I think you have missed the 'drop' argument to matrix indexing, which defaults to TRUE. Maybe it would have been better to have FALSE as the default, but lots of code makes use of it. And you DO have a choice that you seem unaware of. See ?`[`, for example, or any good book on R.> > Thanks, > CMHJ > <<insert bug report here>> > > > > --please do not edit the information below-- > > Version: > platform = x86_64-unknown-linux-gnu > arch = x86_64 > os = linux-gnu > system = x86_64, linux-gnu > status > major = 2 > minor = 7.1 > year = 2008 > month = 06 > day = 23 > svn rev = 45970 > language = R > version.string = R version 2.7.1 (2008-06-23) > > Locale: > LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C > > Search Path: > .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Thomas Lumley
2008-Aug-13 15:22 UTC
[Rd] Column name disappears when indexing a single column (PR#12532)
1. This is not a bug (as you seem to realize), so it should not be sent to r-bugs. 2. You seem to want the drop=FALSE argument to [], as in FAQ 7.5 -thomas On Wed, 13 Aug 2008 cherrera at cs.nmsu.edu wrote:> Good Day, > I can understand that after indexing a single column in a matrix, R will return a vector instead of the single column. However, during the conversion to a vector, the column name is lost. > I was wondering if it would be better to have R return a single column matrix (retaining the column name), instead of automatically converting to a vector. Users could use as.vector() to convert afterwards. > > Thanks, > CMHJ > <<insert bug report here>> > > > > --please do not edit the information below-- > > Version: > platform = x86_64-unknown-linux-gnu > arch = x86_64 > os = linux-gnu > system = x86_64, linux-gnu > status > major = 2 > minor = 7.1 > year = 2008 > month = 06 > day = 23 > svn rev = 45970 > language = R > version.string = R version 2.7.1 (2008-06-23) > > Locale: > LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=C;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C > > Search Path: > .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle