[R] converting a table to a dataframe or a matrix
markleeds at verizon.net
markleeds at verizon.net
Wed Jun 4 21:20:38 CEST 2008
can someone show me how to convert a table to a data.frame or a matrix ?
I tried below and as.data.frame rearranges the columns
similarly to a melt from reshape and as.matrix didn't change it. I
actually would prefer to change it to a dataframe but if someone
can show me how to convert it to a matrix, then as.data.frame will work
on that. I was thinking about just changing the class to matrix
since table looks very similar to a matrix but I wasn't sure if that
would cause side injuries. thanks.
temp <- structure(c(0.345901639344262, 0.360117302052786,
0.354304635761589,
0.354319180087848, 0.365524402907580, 0.359455958549223,
0.340284360189573,
0.369763205828780, 0.304918032786885, 0.304985337243402,
0.310596026490066,
0.287457296242069, 0.285565939771547, 0.264248704663212,
0.297630331753555,
0.231329690346084, 0.349180327868852, 0.334897360703812,
0.335099337748344,
0.358223523670083, 0.348909657320872, 0.376295336787565,
0.362085308056872,
0.398907103825137), class = "table", .Dim = c(8L, 3L), .Dimnames =
structure(list(
c("(-1,-0.75]", "(-0.75,-0.5]", "(-0.5,-0.25]", "(-0.25,0]",
"(0,0.25]", "(0.25,0.5]", "(0.5,0.75]", "(0.75,1]"), c("0",
"1", "2")), .Names = c("", "")))
print(temp)
tempa <- as.data.frame(temp)
tempb <- as.matrix(temp)
print(str(tempa))
print(str(tempb))
More information about the R-help
mailing list