dta <- read.table("C:/tmp/probeL.txt", header=T , stringsAsFactor=F, fill=T )
head(dta)
##    ID Response_Time Position
## 1 S01            51        1
## 2 S01            36        2
## 3 S01            50        3
## 4 S01            35        4
## 5 S01            42        5
## 6 S02            27        1
##借tidyr語法
library(tidyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
##老師上課用的分行命名方式
dta %>% mutate(Position = case_when(Position == 1 ~ "Pos_1",Position == 2 ~ "Pos_2",Position == 3 ~ "Pos_3",Position == 4 ~ "Pos_4",Position == 5 ~ "Pos_5")) %>%
  dplyr::select(Response_Time, Position) %>%
  head
##   Response_Time Position
## 1            51    Pos_1
## 2            36    Pos_2
## 3            50    Pos_3
## 4            35    Pos_4
## 5            42    Pos_5
## 6            27    Pos_1
##展開Ecdat安裝檔
pacman::p_load(Ecdat)
##指定Caschool數據集
dta <- Ecdat::Caschool
head(dta)
##   distcod  county                        district grspan enrltot teachers
## 1   75119 Alameda              Sunol Glen Unified  KK-08     195    10.90
## 2   61499   Butte            Manzanita Elementary  KK-08     240    11.15
## 3   61549   Butte     Thermalito Union Elementary  KK-08    1550    82.90
## 4   61457   Butte Golden Feather Union Elementary  KK-08     243    14.00
## 5   61523   Butte        Palermo Union Elementary  KK-08    1335    71.50
## 6   62042  Fresno         Burrel Union Elementary  KK-08     137     6.40
##   calwpct mealpct computer testscr   compstu  expnstu      str    avginc
## 1  0.5102  2.0408       67  690.80 0.3435898 6384.911 17.88991 22.690001
## 2 15.4167 47.9167      101  661.20 0.4208333 5099.381 21.52466  9.824000
## 3 55.0323 76.3226      169  643.60 0.1090323 5501.955 18.69723  8.978000
## 4 36.4754 77.0492       85  647.70 0.3497942 7101.831 17.35714  8.978000
## 5 33.1086 78.4270      171  640.85 0.1280899 5235.988 18.67133  9.080333
## 6 12.3188 86.9565       25  605.55 0.1824818 5580.147 21.40625 10.415000
##       elpct readscr mathscr
## 1  0.000000   691.6   690.0
## 2  4.583333   660.5   661.9
## 3 30.000002   636.3   650.9
## 4  0.000000   651.9   643.5
## 5 13.857677   641.8   639.9
## 6 12.408759   605.7   605.4
##了解Caschool內容物
names(Caschool)
##  [1] "distcod"  "county"   "district" "grspan"   "enrltot"  "teachers"
##  [7] "calwpct"  "mealpct"  "computer" "testscr"  "compstu"  "expnstu" 
## [13] "str"      "avginc"   "elpct"    "readscr"  "mathscr"
##tidyr加上老師固定語法提供真的相對好用
library(tidyr)
library(dplyr)

##設定隨機取樣
set.seed(99999)

##繪製數學和閱讀散佈圖
dta %>% dplyr::transmute(mathscr, readscr) %T>%
  plot(., xlab="readscr Status", ylab="mathscr score", pch='.') %>% colMeans

##  mathscr  readscr 
## 653.3426 654.9705