Skip Headers

SAS  SPSS  R-PROJECT  S-PLUS  PROC-SQL

통 계
프 로 그 램 비 교

Go to Documentation Home
HOME
Go to Book List
PRO_home
Go to Table of Contents
연구회
Go to Index
자료실
Go to Master Index
R-PROJECT
Go to Feedback page
MAIL

Go to previous page
Previous
Go to next page
Next

15. 변수 라벨(Variable Labels)


1. SAS
2. SPSS
3. R-PROJECT
4. S-PLUS
5. PROC SQL

 


1. SAS

MAIN

 

* SAS Program for Variable Labels;

DATA mydata; 

 SET BACK.mydata ;

     LABEL Q1="문제1"

           Q2="문제2"

           Q3="문제3"

           Q4="문제4";

run;

PROC FREQ;

     TABLES q1-q4;

RUN;

문제1

                              누적       누적

q1      빈도      백분율      빈도      백분율

----------------------------------------------

 1           1     12.50           1     12.50

 2           2     25.00           3     37.50

 3           1     12.50           4     50.00

 4           2     25.00           6     75.00

 5           2     25.00           8    100.00

 

                     문제2

                              누적       누적

q2      빈도      백분율      빈도      백분율

----------------------------------------------

 1           3     37.50           3     37.50

 2           1     12.50           4     50.00

 3           1     12.50           5     62.50

 4           1     12.50           6     75.00

 5           2     25.00           8    100.00



2. SPSS

 

* SPSS Program for Variable Labels.

VARIABLE LABELS

  Q1 "문제1"

  Q2 "문제2"

  Q3 "문제3"

  Q4 "문제4".

FREQUENCIES  VARIABLES=q1 q2 q3 q4.

EXECUTE.

 


3. R-PROJECT

MAIN

*

# 변수 라벨을 위한 R-Project 프로그램.

load(file="c:\\mydata.Rdata")

print(mydata)

 

# Hmisc Label함수 이용.

library(Hmisc)

label(mydata$q1)<-"The instructor was well prepared."

label(mydata$q2)<-"The instructor communicated well."

label(mydata$q3)<-"The course materials were helpful."

label(mydata$q4)<- "Overall, I found this workshop useful."

 

# Hmisc describe함수는 변수 라벨을 이용.

describe(mydata)

mydata

 6  Variables      8  Observations

---------------------------------------------------------------------------

workshop

      n missing  unique    Mean

      8       0       2     1.5

1 (4, 50%), 2 (4, 50%)

---------------------------------------------------------------------------

gender

      n missing  unique

      8       0       2

f (4, 50%), m (4, 50%)

---------------------------------------------------------------------------

q1 : The instructor was well prepared.

      n missing  unique    Mean

      8       0       5    3.25

           1  2  3  4  5

Frequency  1  2  1  2  2

%         12 25 12 25 25

 

# Summary 함수는 라벨을 무시한다.

summary(mydata)

workshop   gender       q1             q2             q3              q4     

 Min.   :1.0   f:4    Min.   :1.00   Min.   :1.00   Min.   :2.000   Min.   :1.00 

 1st Qu.:1.0   m:4    1st Qu.:2.00   1st Qu.:1.00   1st Qu.:4.000   1st Qu.:2.50 

 Median :1.5          Median :3.50   Median :2.50   Median :4.000   Median :3.50 

 Mean   :1.5          Mean   :3.25   Mean   :2.75   Mean   :4.143   Mean   :3.25 

 3rd Qu.:2.0          3rd Qu.:4.25   3rd Qu.:4.25   3rd Qu.:5.000   3rd Qu.:4.25 

 Max.   :2.0          Max.   :5.00   Max.   :5.00   Max.   :5.000   Max.   :5.00

                                                    NA's   :1.000 

 

# 변수 라벨로써 실행하기 위해서 변수 이름을 할당.

names(mydata) <- c("Workshop","Gender",

                   "The instructor was well prepared.",

                   "The instructor communicated well.",

                   "The course materials were helpful.",

                   "Overall, I found this workshop useful.")

names(mydata)

[1] "Workshop"                             

[2] "Gender"                               

[3] "The instructor was well prepared."    

[4] "The instructor communicated well."    

[5] "The course materials were helpful."   

[6] "Overall, I found this workshop useful."

 

# 변수 라벨로 실행하기 위해서 변수 이름을 할당.

# 위의 예제는 모든 변수명을 할당하였으나, 여기서는 부분 변수명을 할당.

names(mydata)[3:6] <- c("The instructor was well prepared.",

                        "The instructor communicated well.",

                        "The course materials were helpful.",

                        "Overall, I found this workshop useful.")

names(mydata)

[1] "Workshop"                             

[2] "Gender"                               

[3] "The instructor was well prepared."    

[4] "The instructor communicated well."    

[5] "The course materials were helpful."   

[6] "Overall, I found this workshop useful."

 

# Summary하면, R함수는 변수명을 사용.

summary(mydata)

Workshop   Gender The instructor was well prepared.    The instructor communicated well.

 Min.   :1.0   f:4    Min.   :1.00                      Min.   :1.00                    

 1st Qu.:1.0   m:4    1st Qu.:2.00                      1st Qu.:1.00                     

 Median :1.5          Median :3.50                      Median :2.50                     

 Mean   :1.5          Mean   :3.25                      Mean   :2.75                     

 3rd Qu.:2.0          3rd Qu.:4.25                      3rd Qu.:4.25                     

 Max.   :2.0          Max.   :5.00                      Max.   :5.00                     

                                                      

The course materials were helpful.                      Overall, I found this workshop useful.

Min.   :2.000                                           Min.   :1.00                         

1st Qu.:4.000                                           1st Qu.:2.50                          

Median :4.000                                           Median :3.50                         

Mean   :4.143                                           Mean   :3.25                         

3rd Qu.:5.000                                           3rd Qu.:4.25                         

Max.   :5.000                                           Max.   :5.00

NA's   :1.000                    

 

# 변수명에 의해 변수를 선택할수 있다.

summary( mydata["Overall, I found this workshop useful."] )

Overall, I found this workshop useful.

 Min.   :1.00                         

 1st Qu.:2.50                         

 Median :3.50                         

 Mean   :3.25                         

 3rd Qu.:4.25                          

 Max.   :5.00

 

# 인덱스를 이용하여 선택하는 것이 편하다.

summary(mydata[3:6])

The instructor was well prepared. The instructor communicated well.

 Min.   :1.00                      Min.   :1.00                    

 1st Qu.:2.00                      1st Qu.:1.00                    

 Median :3.50                      Median :2.50                    

 Mean   :3.25                      Mean   :2.75                    

 3rd Qu.:4.25                      3rd Qu.:4.25                     

 Max.   :5.00                      Max.   :5.00                    

                                                                   

 The course materials were helpful. Overall, I found this workshop useful.

 Min.   :2.000                      Min.   :1.00                         

 1st Qu.:4.000                      1st Qu.:2.50                         

 Median :4.000                      Median :3.50                         

 Mean   :4.143                      Mean   :3.25                          

 3rd Qu.:5.000                      3rd Qu.:4.25                         

 Max.   :5.000                      Max.   :5.00                         

 NA's   :1.000

 

# Grep함수를 이용하여 명에서 문자열에 대한 검색을 할수 있다.

myvars<-grep('instructor',names(mydata))

 

# 'instructor' 소유한 변수 3 4 출력.

print(myvars)

[1] 3 4

 

summary ( mydata[myvars] )

The instructor was well prepared. The instructor communicated well.

 Min.   :1.00                      Min.   :1.00                    

 1st Qu.:2.00                      1st Qu.:1.00                    

 Median :3.50                      Median :2.50                    

 Mean   :3.25                      Mean   :2.75                    

 3rd Qu.:4.25                      3rd Qu.:4.25                    

 Max.   :5.00                      Max.   :5.00

 

 


4. S-PLUS

MAIN

 

 

mydata<-read.table ("c:/data/mydata.csv",header=TRUE,

  sep=",",row.names="id")

print(mydata)

 

# 변수 라벨로써 실행하기 위해서 변수 이름을 할당.

names(mydata) <- c("Workshop","Gender",

                   "The instructor was well prepared.",

                   "The instructor communicated well.",

                   "The course materials were helpful.",

                   "Overall, I found this workshop useful.")

names(mydata)

[1] "Workshop"                             

[2] "Gender"                               

[3] "The instructor was well prepared."    

[4] "The instructor communicated well."    

[5] "The course materials were helpful."   

[6] "Overall, I found this workshop useful."

 

# 변수 라벨로 실행하기 위해서 변수 이름을 할당.

# 위의 예제는 모든 변수명을 할당하였으나, 여기서는 부분 변수명을 할당.

names(mydata)[3:6] <- c("The instructor was well prepared.",

                        "The instructor communicated well.",

                        "The course materials were helpful.",

                        "Overall, I found this workshop useful.")

names(mydata)

[1] "Workshop"                             

[2] "Gender"                               

[3] "The instructor was well prepared."    

[4] "The instructor communicated well."    

[5] "The course materials were helpful."   

[6] "Overall, I found this workshop useful."

 

# Summary하면, R함수는 변수명을 사용.

summary(mydata)

Workshop   Gender The instructor was well prepared.    The instructor communicated well.

 Min.   :1.0   f:4    Min.   :1.00                      Min.   :1.00                    

 1st Qu.:1.0   m:4    1st Qu.:2.00                      1st Qu.:1.00                     

 Median :1.5          Median :3.50                      Median :2.50                     

 Mean   :1.5          Mean   :3.25                      Mean   :2.75                     

 3rd Qu.:2.0          3rd Qu.:4.25                      3rd Qu.:4.25                     

 Max.   :2.0          Max.   :5.00                      Max.   :5.00                     

                                                      

The course materials were helpful.                      Overall, I found this workshop useful.

Min.   :2.000                                           Min.   :1.00                         

1st Qu.:4.000                                           1st Qu.:2.50                          

Median :4.000                                           Median :3.50                         

Mean   :4.143                                           Mean   :3.25                         

3rd Qu.:5.000                                           3rd Qu.:4.25                         

Max.   :5.000                                           Max.   :5.00

NA's   :1.000                    

 

# 변수명에 의해 변수를 선택할수 있다.

summary( mydata["Overall, I found this workshop useful."] )

Overall, I found this workshop useful.

 Min.   :1.00                         

 1st Qu.:2.50                         

 Median :3.50                         

 Mean   :3.25                         

 3rd Qu.:4.25                          

 Max.   :5.00

 

# 인덱스를 이용하여 선택하는 것이 편하다.

summary(mydata[3:6])

The instructor was well prepared. The instructor communicated well.

 Min.   :1.00                      Min.   :1.00                    

 1st Qu.:2.00                      1st Qu.:1.00                    

 Median :3.50                      Median :2.50                    

 Mean   :3.25                      Mean   :2.75                    

 3rd Qu.:4.25                      3rd Qu.:4.25                     

 Max.   :5.00                      Max.   :5.00                    

                                                                   

 The course materials were helpful. Overall, I found this workshop useful.

 Min.   :2.000                      Min.   :1.00                         

 1st Qu.:4.000                      1st Qu.:2.50                         

 Median :4.000                      Median :3.50                         

 Mean   :4.143                      Mean   :3.25                          

 3rd Qu.:5.000                      3rd Qu.:4.25                         

 Max.   :5.000                      Max.   :5.00                         

 NA's   :1.000

 

# Grep함수를 이용하여 명에서 문자열에 대한 검색을 할수 있다.

myvars<-grep('instructor',names(mydata))

 

# 'instructor' 소유한 변수 3 4 출력.

print(myvars)

[1] 3 4

 

summary ( mydata[myvars] )

The instructor was well prepared. The instructor communicated well.

 Min.   :1.00                      Min.   :1.00                    

 1st Qu.:2.00                      1st Qu.:1.00                    

 Median :3.50                      Median :2.50                    

 Mean   :3.25                      Mean   :2.75                    

 3rd Qu.:4.25                      3rd Qu.:4.25                    

 Max.   :5.00                      Max.   :5.00

 

 


5. PROC SQL

MAIN


proc sql;

  select id,

         workshop ,

         gender   ,

         q1       label='The instructor was well prepared.',

         q2       label='The instructor communicated well.',

         q3       label='The course materials were helpful.',

         q4       label='Overall, I found this workshop useful.'

  from   BACK.mydata;

quit;

The  Overall,

                               The           The     course   I found

                        instructor    instructor  materials      this

                          was well  communicated       were  workshop

id  workshop  gender     prepared.         well.   helpful.   useful.

---------------------------------------------------------------------

 1         1  f                  1             1          5         1

 2         2  f                  2             1          4         1

 3         1  f                  2             2          4         3

 4         2  f                  3             1          .         3

 5         1  m                  4             5          2         4

 6         2  m                  5             4          5         5

 7         1  m                  5             3          4         4

 8         2  m                  4             5          5         5