Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recreating nested frequency tables fast

Tags:

r

I find myself recreating nested frequency tables over and over again from articles using matrix and recreating tables (or sometimes giving up and using rep and making the full data set which is very time consuming. I'm looking for the fastest way (least code) to recreate this nested frequency table in R (I assume this is a question that many can benefit from).

              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

This was created using ftable if that's helpful.

Thank you in advance.

like image 255
Tyler Rinker Avatar asked Feb 18 '26 01:02

Tyler Rinker


1 Answers

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"))
like image 84
A5C1D2H2I1M1N2O1R2T1 Avatar answered Feb 19 '26 15:02

A5C1D2H2I1M1N2O1R2T1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!