Hi everybody, I wanted to name a column vector (a variable). This is what I did : try<-matrix(1:4,nrow=4,ncol=1) attr(try,"dimnames")<-list(NULL,"true value") Is it OK ? Thanks for your help, Jimmy [[alternative HTML version deleted]]
On Wed, Aug 18, 2010 at 8:58 AM, Jimmy S?derly <jimmy.soderly at gmail.com> wrote:> Hi everybody, > > I wanted to name a column vector (a variable). > > This is what I did : > > try<-matrix(1:4,nrow=4,ncol=1) > attr(try,"dimnames")<-list(NULL,"true value") > > Is it OK ?Sure. You can also do: dimnames(try) <- list(NULL,"true value") or if you are creating the matrix, directly with: try <- matrix(1:4, nrow = 4, ncol = 1, dimnames = list(NULL, "true value")> > Thanks for your help, > Jimmy > > ? ? ? ?[[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. >-- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/
On Aug 18, 2010, at 11:58 AM, Jimmy S?derly wrote:> Hi everybody, > > I wanted to name a column vector (a variable). > > This is what I did : > > try<-matrix(1:4,nrow=4,ncol=1)("try" is a bad name for an object because it is a useful function name.)> attr(try,"dimnames")<-list(NULL,"true value") > > Is it OK ?Single column matrices get automatically converted to vectors unless you use drop=FALSE. Furthermore naming vectors with strings that contain spaces is possible but unwise , because you will forever be needing to stick quotes around what would otherwise not need the quotes> > Thanks for your help, > Jimmy > > [[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.David Winsemius, MD West Hartford, CT
On 08/18/2010 06:20 PM, Joshua Wiley wrote:> matrix(1:4, nrow = 4, ncol = 1, dimnames = list(NULL, "true value")) >or even cbind("true value"=1:4) -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
It seems like a disastrous proposition to name anything "try", because "try" is a key function used for error handling. Many functions use it internally, and I don't think you'd want to risk fouling up those mechanics! Even if it works, it's confusing to see that function being used as a variable name. On Wed, Aug 18, 2010 at 10:58 AM, Jimmy Söderly <jimmy.soderly@gmail.com>wrote:> Hi everybody, > > I wanted to name a column vector (a variable). > > This is what I did : > > try<-matrix(1:4,nrow=4,ncol=1) > attr(try,"dimnames")<-list(NULL,"true value") > > Is it OK ? > > Thanks for your help, > Jimmy > > [[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. >[[alternative HTML version deleted]]