On this RMarkdown I’m going to show the results of the second part of the assignment #5, where I have to create ordered factor variables for the Excel, Statistics and Programming Variables.

Firs of all, we mark the package readr and read the base undergrad.csv

library(readr)
undergrad <- read_csv("undergrad.csv")
## Rows: 39 Columns: 11
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (8): Timestamp, The following tools are important to my future career. [...
## dbl (3): How likely are you to take another information systems course at St...
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(undergrad)

Once we have our data, lets order the variables Excel, Statistics and Programming. First of all, we need to rename the Variables

names(undergrad)<-c("timestamp","excel","access","statistics","programming","iscourse","cscourse","topics","istopics","onlinecourse","concentration")

Let’s see how it’s organized now

View(undergrad)

To work with data.frame “undergrad” variables directly without explicitly referencing the name of the data frame, let’s use the function Attach() and take a view of the variables Excel, Statistics and Programming

attach(undergrad)
excel
##  [1] "Agree"          "Strongly Agree" "Strongly Agree" "Strongly Agree"
##  [5] "Agree"          "Agree"          "Somewhat agree" "Strongly Agree"
##  [9] "Strongly Agree" "Strongly Agree" "Strongly Agree" "Strongly Agree"
## [13] "Strongly Agree" "Somewhat agree" "Strongly Agree" "Strongly Agree"
## [17] "Somewhat agree" "Agree"          "Strongly Agree" "Strongly Agree"
## [21] "Agree"          "Strongly Agree" "Strongly Agree" "Strongly Agree"
## [25] "Agree"          "Agree"          "Strongly Agree" "Strongly Agree"
## [29] "Strongly Agree" "Strongly Agree" "Agree"          "Strongly Agree"
## [33] "Strongly Agree" "Strongly Agree" "Agree"          "Strongly Agree"
## [37] "Strongly Agree" "Strongly Agree" "Strongly Agree"
statistics
##  [1] "Neither agree or disagree" "Somewhat agree"           
##  [3] "Strongly Agree"            "Strongly Agree"           
##  [5] "Strongly Agree"            "Somewhat agree"           
##  [7] "Agree"                     "Agree"                    
##  [9] "Strongly Agree"            "Somewhat agree"           
## [11] "Strongly Agree"            "Strongly Agree"           
## [13] "Somewhat agree"            "Somewhat agree"           
## [15] "Agree"                     "Agree"                    
## [17] "Agree"                     "Neither agree or disagree"
## [19] "Strongly Agree"            "Strongly Agree"           
## [21] "Agree"                     "Strongly Agree"           
## [23] "Agree"                     "Somewhat agree"           
## [25] "Agree"                     NA                         
## [27] "Somewhat agree"            "Strongly Agree"           
## [29] "Agree"                     "Strongly Agree"           
## [31] "Disagree"                  "Strongly Agree"           
## [33] "Strongly Agree"            "Agree"                    
## [35] "Agree"                     "Agree"                    
## [37] "Agree"                     "Strongly Agree"           
## [39] "Strongly Agree"
programming
##  [1] "Neither agree or disagree" "Strongly Agree"           
##  [3] "Strongly Agree"            "Agree"                    
##  [5] "Agree"                     "Somewhat agree"           
##  [7] "Strongly Agree"            "Strongly Agree"           
##  [9] "Somewhat agree"            "Somewhat disagree"        
## [11] "Agree"                     "Strongly Agree"           
## [13] "Strongly Agree"            "Somewhat disagree"        
## [15] "Agree"                     "Somewhat agree"           
## [17] "Strongly Agree"            "Neither agree or disagree"
## [19] "Strongly Agree"            "Agree"                    
## [21] "Agree"                     "Strongly Agree"           
## [23] "Agree"                     "Somewhat agree"           
## [25] "Neither agree or disagree" "Neither agree or disagree"
## [27] "Somewhat agree"            "Strongly Agree"           
## [29] "Agree"                     "Agree"                    
## [31] "Disagree"                  "Strongly Agree"           
## [33] "Agree"                     "Agree"                    
## [35] "Agree"                     "Somewhat agree"           
## [37] "Neither agree or disagree" "Strongly Agree"           
## [39] "Strongly Agree"

OK now I’m going to show how is tabulated each variable with the function table(), where the first row means the scale of evaluation and the second row means the frequency of each evaluation.

table(excel)
## excel
##          Agree Somewhat agree Strongly Agree 
##              9              3             27
table(statistics)
## statistics
##                     Agree                  Disagree Neither agree or disagree 
##                        13                         1                         2 
##            Somewhat agree            Strongly Agree 
##                         7                        15
table(programming)
## programming
##                     Agree                  Disagree Neither agree or disagree 
##                        12                         1                         5 
##            Somewhat agree         Somewhat disagree            Strongly Agree 
##                         6                         2                        13

Now we can order the variables as they are ordinal variables, this means that there is a relationship between the levels. To order the variables we are going to use the ordered() function.

statistics_ordered<-ordered(statistics,c("Strongly disagree","Disagree","Somewhat disagree","Neither agree or disagree","Somewhat agree","Agree","Strongly Agree"))
programming_ordered<-ordered(programming,c("Strongly disagree","Disagree","Somewhat disagree","Neither agree or disagree","Somewhat agree","Agree","Strongly Agree"))
excel_ordered<-ordered(excel,c("Strongly disagree","Disagree","Somewhat disagree","Neither agree or disagree","Somewhat agree","Agree","Strongly Agree"))

Let’s validate the order of the variables

attributes(excel_ordered)
## $levels
## [1] "Strongly disagree"         "Disagree"                 
## [3] "Somewhat disagree"         "Neither agree or disagree"
## [5] "Somewhat agree"            "Agree"                    
## [7] "Strongly Agree"           
## 
## $class
## [1] "ordered" "factor"
attributes(statistics_ordered)
## $levels
## [1] "Strongly disagree"         "Disagree"                 
## [3] "Somewhat disagree"         "Neither agree or disagree"
## [5] "Somewhat agree"            "Agree"                    
## [7] "Strongly Agree"           
## 
## $class
## [1] "ordered" "factor"
attributes(programming_ordered)
## $levels
## [1] "Strongly disagree"         "Disagree"                 
## [3] "Somewhat disagree"         "Neither agree or disagree"
## [5] "Somewhat agree"            "Agree"                    
## [7] "Strongly Agree"           
## 
## $class
## [1] "ordered" "factor"

Now the variables are in order, let’s recreate our frequency table

table(excel_ordered)
## excel_ordered
##         Strongly disagree                  Disagree         Somewhat disagree 
##                         0                         0                         0 
## Neither agree or disagree            Somewhat agree                     Agree 
##                         0                         3                         9 
##            Strongly Agree 
##                        27
table(programming_ordered)
## programming_ordered
##         Strongly disagree                  Disagree         Somewhat disagree 
##                         0                         1                         2 
## Neither agree or disagree            Somewhat agree                     Agree 
##                         5                         6                        12 
##            Strongly Agree 
##                        13
table(statistics_ordered)
## statistics_ordered
##         Strongly disagree                  Disagree         Somewhat disagree 
##                         0                         1                         0 
## Neither agree or disagree            Somewhat agree                     Agree 
##                         2                         7                        13 
##            Strongly Agree 
##                        15

Now finally we can a histogram or other graphs for the undergrad data. Let’s do a histogram for each variable

figure01<-hist(as.numeric(excel_ordered),breaks = 7,main = "Excel is an important tool for my future carrer",xlab = "Bins by response category",col = "#4cba14",labels = TRUE,border = "#FFFFFF")

figure02<-hist(as.numeric(statistics_ordered),breaks = 7,main = "Statistics is an important tool for my future carrer",xlab = "Bins by response category",col = "#4cba14",labels = TRUE,border = "#FFFFFF")

figure03<-hist(as.numeric(programming_ordered),breaks = 7,main = "Programming is an important tool for my future carrer",xlab = "Bins by response category",col = "#4cba14",labels = TRUE,border = "#FFFFFF")

Thanks