Re: [R] data.frame() versus as.data.frame() applied to a matrix.

2019-02-05 Thread William Dunlap via R-help
I think of the methods of as.data.frame as a helper functions for data.frame and don't usually call as.data.frame directly. data.frame() will call as.data.frame for each of its arguments and then put together the the results into one big data.frame. > for(method in

Re: [R] data.frame() versus as.data.frame() applied to a matrix.

2019-02-05 Thread Richard M. Heiberger
To me the interesting difference between matrix() and as.matrix() is that as.matrix() retains the argument names as the rows names of the result. > tmp <- structure(1:3, names=letters[1:3]) > tmp a b c 1 2 3 > matrix(tmp) [,1] [1,]1 [2,]2 [3,]3 > as.matrix(tmp) [,1] a1 b

Re: [R] data.frame() versus as.data.frame() applied to a matrix.

2019-02-05 Thread Rolf Turner
On 2/6/19 12:27 PM, Jeff Newmiller wrote: I have no idea about "why it is this way" but there are many cases where I would rather have to use backticks around syntactically-invalid names than deal with arbitrary rules for mapping column names as they were supplied to column names as R wants

Re: [R] data.frame() versus as.data.frame() applied to a matrix.

2019-02-05 Thread Jeff Newmiller
I have no idea about "why it is this way" but there are many cases where I would rather have to use backticks around syntactically-invalid names than deal with arbitrary rules for mapping column names as they were supplied to column names as R wants them to be. From that perspective, making the

[R] data.frame() versus as.data.frame() applied to a matrix.

2019-02-05 Thread Rolf Turner
Consider the following: set.seed(42) X <- matrix(runif(40),10,4) colnames(X) <- c("a","b","a:x","b:x") # Imitating the output # of model.matrix(). D1 <- as.data.frame(X) D2 <- data.frame(X) names(D1) [1] "a" "b" "a:x" "b:x" names(D2) [1] "a" "b"