[R] Cross tabulation with top one variable and side as multiple variables

jagadishpchary p.jagadish at inrhythm-inc.com
Thu Jun 18 08:46:24 CEST 2015


I think my explanation in the post is not giving the full details on the job
to be done. Sorry for that. Here is what I am doing..

1.	I have a SPSS data set with more than 2000 variables. However for test
purpose I have created a temporary data set with 5 variables which I am
reading it to R environment (Attached the test.sav file).
2.	There is a variable called “TREND” which has the year data. So all I need
to do is cross tabulate the variables with this Trend variable. 
In SPSS the syntax would be

CTABLES
/VLABELS VARIABLES =ALL DISPLAY=LABEL
/TABLES (AGET +SEXT +EDUCRT +JOBRT ) [COUNT F40.0] by TREND.

The final cross tabulation results are placed in the attached excel report
with sheet name “Results”.

As I am new to R  - I tried searching the forums for the cross tabulation
with top variable constant and multiple variables as side however I could
not find it. Anyhow I tried using the below syntax :

Xtabs ( ~ AGET +SEXT +EDUCRT +JOBRT + TREND, data=mydata)
summary(~AGET +SEXT +EDUCRT +JOBRT, data= mydata, fun=table)
ftable (mydata, row.vars=c("AGET ", " SEXT ", " EDUCRT " , “JOBRT”),
col.vars="TREND")

the results are not identical to what I am getting in SPSS

Hence I would request to suggest me a R code that helps me in getting the
results as shown in the attached excel report with sheet name “Results”.
Test.sav <http://r.789695.n4.nabble.com/file/n4708799/Test.sav>  
Cross_tabulation.xlsx
<http://r.789695.n4.nabble.com/file/n4708799/Cross_tabulation.xlsx>  




--
View this message in context: http://r.789695.n4.nabble.com/Cross-tabulation-with-top-one-variable-and-side-as-multiple-variables-tp4708379p4708799.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list