[R] str and structable error
Hallo I encountered a behaviour which puzzles me (but finally I did get what I wanted). I used structable and strucplot but I wanted to change names of variables in structable object. I tried to subset it, use names but to no avail. So I tried str and expected to get a structure of an object but: sss-structable(Titanic) str(sss) Error in [.structable(x, args[[1]], ) : subscript out of bounds Finally I learned, that I need to change attributes of structable object. Is this error message OK and I did not read documentation properly? Or is it normal that str gives an error on some objects but I just was not so lucky to meet one?. W2000, R2.2.0, vcd package Built: R 2.2.0; ; 2005-11- 22 14:23:44; windows, Best regards. Petr Petr Pikal [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] str and structable error
Petr Pikal wrote: Hallo I encountered a behaviour which puzzles me (but finally I did get what I wanted). I used structable and strucplot but I wanted to change names of variables in structable object. I tried to subset it, use names but to no avail. So I tried str and expected to get a structure of an object but: sss-structable(Titanic) str(sss) Error in [.structable(x, args[[1]], ) : subscript out of bounds Looks like package vcd needs a separate structable method for the str() generic. Uwe Ligges Finally I learned, that I need to change attributes of structable object. Is this error message OK and I did not read documentation properly? Or is it normal that str gives an error on some objects but I just was not so lucky to meet one?. W2000, R2.2.0, vcd package Built: R 2.2.0; ; 2005-11- 22 14:23:44; windows, Best regards. Petr Petr Pikal [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] str and structable error
Petr == Petr Pikal [EMAIL PROTECTED] on Mon, 28 Nov 2005 08:38:07 +0100 writes: Petr Hallo I encountered a behaviour which puzzles me (but Petr finally I did get what I wanted). Petr I used structable and strucplot but I wanted to change Petr names of variables in structable object. structable is not part of R : You should tell us that you are using an extra package where structable is from : namely -- I did your homework -- vcd Petr I tried to subset it, use names but to no avail. So I Petr tried str and expected to get a structure of an object Petr but: sss-structable(Titanic) str(sss) Petr Error in [.structable(x, args[[1]], ) : subscript Petr out of bounds yes, and similar problems from library(vcd) example(structable) str(hec) -- see below Petr Finally I learned, that I need to change attributes of Petr structable object. Petr Is this error message OK and I did not read Petr documentation properly? Or is it normal that str gives Petr an error on some objects but I just was not so lucky Petr to meet one?. No, it is not normal (and is a bug -- in vcd code IMO): The reason is that structable ``objects'' (S3) do not fulfill a fundamental property that all S (and hence R) objects should fulfill IMO {but read on before protesting} length() and [ should be compatible - namely, for an object 'x', if n - length(x) and assume n 0 for the moment, then x[j] should return something reasonable for all numeric vectors 'j' which have values in {1,2,...,n} (and also for {-n,...,-1}) This is unfortunately not at all true for structable objects. I'd say the authors of structable made a bit a peculiar decision when they designed the [.structable method since that invalidates the above basic principle. This is particularly unfortunate, since structable also inherits from ftable {a ``standard R'' S3 class} which does not have that bad property If the current [ (non-S-like IMO) behavior of structable objects really will be maintained in the future, one solution / workaround would be to define a simple str.structable method -- which would also help you for the moment : str.structable - function(object, ...) { cat(structable ) class(object) - class(object)[-1] str(object, ...) } str(structable(Titanic)) structable ftable [1:8, 1:4] 0 118 0 154 35 387 0 670 5 57 ... - attr(*, dnames)=List of 4 ..$ Class : chr [1:4] 1st 2nd 3rd Crew ..$ Sex : chr [1:2] Male Female ..$ Age : chr [1:2] Child Adult ..$ Survived: chr [1:2] No Yes - attr(*, split_vertical)= logi [1:4] FALSE TRUE FALSE TRUE - attr(*, col.vars)=List of 2 ..$ Sex : chr [1:2] Male Female ..$ Survived: chr [1:2] No Yes - attr(*, row.vars)=List of 2 ..$ Class: chr [1:4] 1st 2nd 3rd Crew ..$ Age : chr [1:2] Child Adult - attr(*, class)= chr ftable Regards, Martin Maechler, ETH Zurich Petr W2000, R2.2.0, vcd package Built: R 2.2.0; ; 2005-11- Petr 22 14:23:44; windows, Petr Best regards. Petr Petr Petr Petr Pikal [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Re: [R] str and structable error
I encountered a behaviour which puzzles me (but finally I did get what I wanted). I used structable and strucplot but I wanted to change names of variables in structable object. I tried to subset it, use names but to no avail. So I tried str and expected to get a structure of an object but: sss-structable(Titanic) str(sss) Error in [.structable(x, args[[1]], ) : subscript out of bounds Looks like package vcd needs a separate structable method for the str() generic. yes! Thanks for pointing this out. It's because [.structable has a non-standard behavior. Using: [.structable = function(object, ...) NextMethod() at the command line, str() would work as expected. David Uwe Ligges Finally I learned, that I need to change attributes of structable object. Is this error message OK and I did not read documentation properly? Or is it normal that str gives an error on some objects but I just was not so lucky to meet one?. W2000, R2.2.0, vcd package Built: R 2.2.0; ; 2005-11- 22 14:23:44; windows, Best regards. Petr Petr Pikal [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html -- Dr. David Meyer Department of Information Systems and Operations Vienna University of Economics and Business Administration Augasse 2-6, A-1090 Wien, Austria, Europe Fax: +43-1-313 36x746 Tel: +43-1-313 36x4393 HP: http://wi.wu-wien.ac.at/~meyer/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html