Hi folks, An Introduction to R 3.3 Getting and setting attributes http://cran.r-project.org/doc/manuals/R-intro.html#Vectors-and-assignment> z <- 0:9 > z[1] 0 1 2 3 4 5 6 7 8 9> attr(z, "dim") <- c(10,10)Error in attr(z, "dim") <- c(10, 10) : dims [product 100] do not match the length of object [10] Please help me to understand what mistake I committed? TIA B.R. Stephen L
On Nov 5, 2010, at 12:05 AM, Stephen Liu wrote:> Hi folks, > > An Introduction to R > > 3.3 Getting and setting attributes > http://cran.r-project.org/doc/manuals/R-intro.html#Vectors-and-assignment > >> z <- 0:9 >> z > [1] 0 1 2 3 4 5 6 7 8 9 > >> attr(z, "dim") <- c(10,10) > Error in attr(z, "dim") <- c(10, 10) : > dims [product 100] do not match the length of object [10] > > Please help me to understand what mistake I committed? TIAIf you want a 10 x 10 matrix then: zm <- matrix(z, 10, 10) # positional arguments to nrow and ncol. If you were trying for something else, then please explain in plain English rather than simply showing code that throws an error. David Winsemius, MD West Hartford, CT
David Winsemius <dwinsemius at comcast.net> [Fri, Nov 05, 2010 at 05:18:23AM CET]: [...]> If you were trying for something else, then please explain in plain > English rather than simply showing code that throws an error. >Well, code never hurts. But it should be accompanied with a hint towards what it is meant to do. -- Johannes H?sing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johannes at huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, "Life on the Mississippi")
David Winsemius
2011-Apr-25 23:18 UTC
[R] Shouldn't this be fixed in the documentation? No.
csmark wrote:> > I know I'm bringing up an old thread but I ran into this exact same > problem. It comes straight out of section 3.3 "Getting & Setting > Attributes" from "An Introduction to R" documentation. > > > http://cran.r-project.org/doc/manuals/R-intro.html#Getting-and-setting-attributes > http://cran.r-project.org/doc/manuals/R-intro.html#Getting-and-setting-attributes > > Earlier in section 3.1 it has "if z is a complex vector of length 100, > then in an expression mode(z) is the character string "complex" and > length(z) is 100." > > The very next assignment is z <- 0:9. > > If one makes a complex array of length 100 via z <- c(1+0i:99+0i) the > attr() function works perfectly. > > Not being fluent in complex numbers I don't quite know how the range > (1+0i:100+0i) has 101 elements but maybe this could be added too. > > Who do we contact to clarify this? Thanks! >First, hit your forehead ... hard, then repeat ten times: "operator precedence" Then go read the FAQ item about this or go to:> ?Syntax..... so you can see what efforts have already been made "to clarify this". -- Daid/ -- View this message in context: http://r.789695.n4.nabble.com/setting-attributes-tp3028152p3474356.html Sent from the R help mailing list archive at Nabble.com.