Re: [R] converting a table to a dataframe or a matrix

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Wed, 04 Jun 2008 16:39:03 -0300

Hi Mark,

Try this:

as.data.frame.matrix(temp)

or

as.data.frame(unclass(temp))

On Wed, Jun 4, 2008 at 4:20 PM, <markleeds_at_verizon.net> wrote:

>
> 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))
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]


______________________________________________ R-help_at_r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

Received on Wed 04 Jun 2008 - 20:36:44 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 04 Jun 2008 - 21:30:49 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive