Quickly recreate nested frequency tables

I recreate nested frequency tables from articles over and over again using the matrix and recreating the tables (or sometimes refusing and using repand making a complete data set that takes a lot of time. I am looking for the fastest (smallest code) to recreate this nested frequency table in R (I assume this is a question that many can learn from this).

              gender female male
hs.grad race                    
no      asian             3    4
        black             5   10
        white            17   11
yes     asian             5    7
        black             1    9
        white            11   17

It was created with help ftable, if useful.

Thanks in advance.

+3
source share
1 answer

Do you mean something like this?

file = tempfile()
cat (text='              gender female male
hs.grad race                    
no      asian             3    4
        black             5   10
        white            17   11
yes     asian             5    7
        black             1    9
        white            11   17
', file=file)
ft = read.ftable(file)

Or

> read.ftable(textConnection("              gender female male
+ hs.grad race                    
+ no      asian             3    4
+         black             5   10
+         white            17   11
+ yes     asian             5    7
+         black             1    9
+         white            11   17"))
+10
source

All Articles