From SAS to R

Download Report

Transcript From SAS to R

From SAS to R
中国人民大学 统计学院
王 剑
你属于哪一类?
既熟悉SAS,又熟悉R
熟悉SAS, 但不熟悉R
不熟悉SAS,但熟悉 R
既不熟悉SAS,也不熟悉 R
SAS和R的本质区别
SAS
R
Reads one observation
at a time
Requires all the data
to be in memory
Code
R
Example=data.frame(
Name=c("Zhao","Wan
g"),
X1=c(22,24),X2=c(98,
96))
mean(Example[,2-3])
Output
Name X1 X2
1 Zhao 22 98
2 Wang 24 96
X1 X2
23 97
SAS
Data Example;
input Name$ X1-X2;
Xm= mean(Of X1-X2);
cards;
Zhao 22 98
Wang 24 96
;
proc print;
run;
Obs Name X1
1
Zhao 22
2
Wang 24
X2
98
96
Xm
60
60
FREE
SAS
R
Data
Structure
Rectangular data set
Rectangular data frame,
vector, matrix, list.
Choosing
data
Analyses can freely
All the data for an
combine variables from
analysis must be in a
different data frames
single data set
or other structures.
Choosing
Observations
Uses logical
conditions in IF,
SELECT IF, WHERE
Uses wide variety of
selection by index
value, variable name,
logical condition
-—— R for SAS SPSS users, Bob Muenchen
SAS的五大部分
Data input and management
statements
Statistical and graphical
procedures
Output Delivery System
A macro language
A matrix language to add
new algorithms(IML)
SAS
Data Example;
input Name$ X1-X2;
Xm= mean(Of X1-X2);
cards;
Zhao 22 98
Wang 24 96
;
proc print;
run;