Stefan Uhmann
2008-Nov-05 10:08 UTC
[R] access (exactly/only) one dimension of a multidimensional table
Dear list, I have a multi(3)dimensional table, which is printed as two tables: > table.a , , = female not at all a little medium heavy no 53 27 8 6 yes 30 67 61 66 , , = male not at all a little medium heavy no 31 20 11 5 yes 5 19 34 25 How can I access (manipulate) only the first table (female)? I want to calculate the percentages for each gender group, i.e. dividing each table/array by the sum of of this table/array. And I want to keep the structure you see, because I use it already for plotting the data. Any suggestions or would I have to stick to the original data? Thanks in advance, Stefan
Henrique Dallazuanna
2008-Nov-05 10:48 UTC
[R] access (exactly/only) one dimension of a multidimensional table
Try this: prop.table(table.a, margin = 3) On Wed, Nov 5, 2008 at 8:08 AM, Stefan Uhmann < stefan.uhmann@mailbox.tu-dresden.de> wrote:> Dear list, > > I have a multi(3)dimensional table, which is printed as two tables: > > > table.a > , , = female > > > not at all a little medium heavy > no 53 27 8 6 > yes 30 67 61 66 > > , , = male > > > not at all a little medium heavy > no 31 20 11 5 > yes 5 19 34 25 > > How can I access (manipulate) only the first table (female)? > I want to calculate the percentages for each gender group, i.e. dividing > each table/array by the sum of of this table/array. And I want to keep the > structure you see, because I use it already for plotting the data. > > Any suggestions or would I have to stick to the original data? > > Thanks in advance, > Stefan > > ______________________________________________ > R-help@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]]
Stefan Uhmann
2008-Nov-05 11:44 UTC
[R] access (exactly/only) one dimension of a multidimensional table
Thank you very much, Jim and Henrique, The solution I expected but was unable to figure out myself was Jim's: table.a[,,1] to access the third dimension. The solution by Henrique was unexpected, bit more specific but perfect for my purpose and very elegant. I will make use of both in the future. Great, thank you again! Stefan Jim Lemon schrieb, Am 05.11.2008 11:53:> Stefan Uhmann wrote: >> Dear list, >> >> I have a multi(3)dimensional table, which is printed as two tables: >> >>> table.a >> , , = female >> >> >> not at all a little medium heavy >> no 53 27 8 6 >> yes 30 67 61 66 >> >> , , = male >> >> >> not at all a little medium heavy >> no 31 20 11 5 >> yes 5 19 34 25 >> >> How can I access (manipulate) only the first table (female)? >> I want to calculate the percentages for each gender group, i.e. >> dividing each table/array by the sum of of this table/array. And I >> want to keep the structure you see, because I use it already for >> plotting the data. >> > Hi Stefan, > Would something like this work? > > 100*table.a[,,1]/rowSums(table.a[,,1]) > > > Jim > >
Apparently Analagous Threads
- Creating subsets of a matrix
- how to calculate another vector based on the data from a combination of two factors
- how to assign fixed factor in lm
- I need to create new variables based on two numeric variables and one dichotomize conditional category variables.
- Help to find only one class and differennt class