On Mon, 9 Feb 2004 17:47:36 -0300, "Gustavo Pinheiro" <gustavo at estatcamp.com.br> wrote :>Hello all, > >I've had trouble converting a data.frame to a matrix (numeric) using either >data.matrix() and as.matrix(). >After executing one of those I end up with another data.frame with only the >first column of the original data.frame. >I use a window (tcltk) to let the user choose the columns he wants and then >I retrieve them using the following: > >varstemp <- .numeric[as.numeric(tkcurselection(subgroupsBox)) + 1] > >where ".numeric" is the original (complete) data.frame. > >Any ideas why is this happening? I'm using R1.8.1 in WinXP by the way.I'd guess "as.numeric(tkcurselection(subgroupsBox)) + 1" isn't returning what you think it's returning, or maybe .numeric isn't in the form you think. I'd also recommend using both row and column indices when working with data frames. What you have selects columns from a data.frame, but not from a matrix (assuming that the index is a vector of integers). I find it's safer to treat data.frames as matrices whenever you can, i.e. use a blank row index varstemp <- .numeric[ , as.numeric(tkcurselection(subgroupsBox)) + 1] Duncan Murdoch
Hello all, I've had trouble converting a data.frame to a matrix (numeric) using either data.matrix() and as.matrix(). After executing one of those I end up with another data.frame with only the first column of the original data.frame. I use a window (tcltk) to let the user choose the columns he wants and then I retrieve them using the following: varstemp <- .numeric[as.numeric(tkcurselection(subgroupsBox)) + 1] where ".numeric" is the original (complete) data.frame. Any ideas why is this happening? I'm using R1.8.1 in WinXP by the way. Thanks.
Dear Gustavo, To fill in other list members, this is occurring with code written to augment the Rcmdr package. The problem is that .numeric is a vector of names of numeric variables in the "active data set" (data frame) maintained by Rcmdr, it is not itself a data frame. Consequently, your varstemp is also a vector of names, which could be used to index the active data set, whose name is stored in .activeDataSet. I hope that this helps, John On Mon, 9 Feb 2004 17:47:36 -0300 "Gustavo Pinheiro" <gustavo at estatcamp.com.br> wrote:> Hello all, > > I've had trouble converting a data.frame to a matrix (numeric) using > either > data.matrix() and as.matrix(). > After executing one of those I end up with another data.frame with > only the > first column of the original data.frame. > I use a window (tcltk) to let the user choose the columns he wants > and then > I retrieve them using the following: > > varstemp <- .numeric[as.numeric(tkcurselection(subgroupsBox)) + 1] > > where ".numeric" is the original (complete) data.frame. > > Any ideas why is this happening? I'm using R1.8.1 in WinXP by the > way. > > Thanks. > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html