Dear sir,
If I have a vector as:
y - c(1:4)
and a matrix as:
x - matrix (5:12, nrow=4, ncol=2)
Then I create a data frame as:
t - data.frame(y, x)
R will generate a data frame of 3 columns
names(t)
y X1 X2
is.vector(t$X1) returns TRUE
is.vector(t$X2) returns TRUE
R splits the columns of a
hi,
because of my ignorance I can't figure out why would you need such a structure.
However the following trick works:
a - matrix(1:6,3)
b - data.frame(1:3)
b$a - a
b
X1.3 a.1 a.2
11 1 4
22 2 5
33 3 6
names(b)
[1] X1.3 a
class(b$a)
[1] matrix
is.matrix(b$a)
[1]
On 2011-06-27 03:02, 新鼎-智慧製造事業處-鄭紹文 wrote:
Dear sir,
If I have a vector as:
y- c(1:4)
and a matrix as:
x- matrix (5:12, nrow=4, ncol=2)
Then I create a data frame as:
t- data.frame(y, x)
R will generate a data frame of 3 columns
names(t)
y X1 X2
is.vector(t$X1) returns TRUE
3 matches
Mail list logo