Apparently row names are dropped when I extract single column from a data frame. Why this behaviour ?
y <- as.matrix(df[,1:2]); length(row.names(y))
[1] 324
y <- as.matrix(df[,1:1]); length(row.names(y))
[1] 0 Best regards, Ryszard
3 messages · ryszard.czerminski@pharma.novartis.com, Marc Schwartz, Brian Ripley
Apparently row names are dropped when I extract single column from a data frame. Why this behaviour ?
y <- as.matrix(df[,1:2]); length(row.names(y))
[1] 324
y <- as.matrix(df[,1:1]); length(row.names(y))
[1] 0 Best regards, Ryszard
On Tue, 2004-03-02 at 11:59, ryszard.czerminski at pharma.novartis.com wrote:
Apparently row names are dropped when I extract single column from a data frame. Why this behaviour ?
y <- as.matrix(df[,1:2]); length(row.names(y))
[1] 324
y <- as.matrix(df[,1:1]); length(row.names(y))
[1] 0 Best regards, Ryszard
Please see R-FAQ 7.7: "Why do my matrices lose dimensions?" HTH, Marc Schwartz
Apparently row names are dropped when I extract single column from a data frame. Why this behaviour ?
y <- as.matrix(df[,1:2]); length(row.names(y))
[1] 324
y <- as.matrix(df[,1:1]); length(row.names(y))
[1] 0
Why are you converting a subsetted data frame to a matrix? df[, 1:2] is a data frame, and df[, 1:1] is a single column (most likely a vector). The latter is not going to have row names, but it might have names. It happens that in S the row names are not copied across as names. row.names applies to a data frame, and not to a matrix, strictly.
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