2016-10-24 96 views
2

在R中,函數table使用交叉分類因子構造一個應急表。是否有可以重現此R函數結果的等效SAS PROC?是否有與SAS中的R函數表相當的功能?

例子:

x <- data.frame(x=rep(1:2,times=5),y=rep(1:2,each=5)) 

# output: x 
# x y 
#1 1 1 
#2 2 1 
#3 1 1 
#4 2 1 
#5 1 1 
#6 2 2 
#7 1 2 
#8 2 2 
#9 1 2 
#10 2 2 

table(x) 

# output: table(x) 
# y 
#x 1 2 
#1 3 2 
#2 2 3 
+1

見'PROC FREQ'。 – Benjamin

回答

2

是, 你想用PROC頻率。

Proc freq data=mydata; 
table x; *gives table of single variable; 
table x*y; *gives a crosstab; 
by z; *will give multiple tables based on levels of z; 
run; 

3個例子。 變量如果定義了糖尿病的任何亞型,糖尿病_最終定義和糖尿病定義爲1。

PROC FREQ DATA=ADS_R; 
TABLE DIABETES_FINAL; 
TABLE DIABETES; 
TABLE DIABETES_FINAL*DIABETES; 
TABLE DIABETES_FINAL*DIABETES/MISSPRINT LIST MISSING; ***SYNTAX FOR STRIPPED DOWN TABLE; 
RUN; 

enter image description here

+0

如果您有機會,可以提供一些示例輸出嗎?謝謝。 –

+0

@JonathanLisic按照要求。 – akaDrHouse

相關問題