I have created a table like this using the R command:
table(Medicine, choose, Period)
I need to make this table to some kind of dataframe so that I can use it in ggplot to make a chart. Is there any way?
I have created a table like this using the R command:
table(Medicine, choose, Period)
I need to make this table to some kind of dataframe so that I can use it in ggplot to make a chart. Is there any way?
The simplest would have been to use data.frame
:
data.frame(table(Medicine, choose, Period))
Unless you are asking for a specific outcome, and can express your desired output, I don't see why the good old data.frame()
wouldn't cut it.
A faceted table:
xtabs(~cyl+gear+am, mtcars)
, , am = 0
gear
cyl 3 4 5
4 1 2 0
6 2 2 0
8 12 0 0
, , am = 1
gear
cyl 3 4 5
4 0 6 2
6 0 2 1
8 0 0 2
And wrapping it in data.frame()
or as.data.frame()
:
data.frame(xtabs(~cyl+gear+am, mtcars))
cyl gear am Freq
1 4 3 0 1
2 6 3 0 2
3 8 3 0 12
4 4 4 0 2
5 6 4 0 2
6 8 4 0 0