#mydata=read.csv(“C:/Users/User/Desktop/LearnR/CA/CAdata/binary.csv”, header=TRUE, sep=“,”)

ctrl+Alt+I 快速插入 新塊 Insert Chunk

ctrl+Shift+c 加注釋#

ctrl+Shift+c 直接knit

遇到UCBAdmissions{datasets}

執行

資料匯入、檢視資料

dta <- read.table("/Users/User/Desktop/DM_R/hk0413/inclass/inclass2/cigarettes.txt", header=T , stringsAsFactor=F, fill=T )
dim(dta)
## [1] 11  3
str(dta)
## 'data.frame':    11 obs. of  3 variables:
##  $ Country    : chr  "Australia" "Canada" "Denmark" "Finland" ...
##  $ consumption: int  480 500 380 1100 1100 230 490 250 300 510 ...
##  $ death      : int  180 150 170 350 460 60 240 90 110 250 ...

網路資料(.dat)匯入

fLoc <- "http://www-stat.stanford.edu/~rag/stat222/BOCKlong.dat"
dta1 <- read.table(fLoc, header = T)
str(dta1)
## 'data.frame':    256 obs. of  4 variables:
##  $ vocab  : num  1.75 0.9 0.8 2.42 -1.31 -1.56 1.09 -1.92 -1.61 2.47 ...
##  $ grade  : int  8 8 8 8 8 8 8 8 8 8 ...
##  $ student: int  1 2 3 4 5 6 7 8 9 10 ...
##  $ isMale : int  1 1 1 1 1 1 1 1 1 1 ...
head(dta1, n = 9); tail(dta1, n = 9)
##   vocab grade student isMale
## 1  1.75     8       1      1
## 2  0.90     8       2      1
## 3  0.80     8       3      1
## 4  2.42     8       4      1
## 5 -1.31     8       5      1
## 6 -1.56     8       6      1
## 7  1.09     8       7      1
## 8 -1.92     8       8      1
## 9 -1.61     8       9      1
##     vocab grade student isMale
## 248  1.16    11      56      0
## 249  2.18    11      57      0
## 250  2.61    11      58      0
## 251  3.91    11      59      0
## 252  1.86    11      60      0
## 253  3.89    11      61      0
## 254  4.98    11      62      0
## 255  2.31    11      63      0
## 256  2.64    11      64      0

在 R markdown中插入圖片png

knitr::include_graphics("C:/Users/User/Desktop/LearnR/2.png")
A caption

A caption

製作伸縮表格(可拉上拉下)

#install.packages("kableExtra")
library(knitr)
library(dplyr)
library(kableExtra)
knitr::opts_chunk$set(echo = TRUE)
options(knit.table.format = "html")
kable(cars) %>% 
  kable_styling() %>%
  scroll_box(height = "200px")
speed dist
4 2
4 10
7 4
7 22
8 16
9 10
10 18
10 26
10 34
11 17
11 28
12 14
12 20
12 24
12 28
13 26
13 34
13 34
13 46
14 26
14 36
14 60
14 80
15 20
15 26
15 54
16 32
16 40
17 32
17 40
17 50
18 42
18 56
18 76
18 84
19 36
19 46
19 68
20 32
20 48
20 52
20 56
20 64
22 66
23 54
24 70
24 92
24 93
24 120
25 85

資料下載轉成自己的檔案

左邊快捷欄位的Rmarkdown模板(網址如下)

https://medium.com/@kstseng/r-markdown-template-a4b0449a56d5

# ---
# title: "Ca7_Logistic Regression_0422"
# author: "Tung-Han Wu"
# date: "2020/4/22"
# output: 
#   html_document: 
#     toc: true
#     toc_depth: 2
#     toc_float:
#         collapsed: false
#         smooth_scroll: false
# ---
  • 標題,單#表示一級標題,雙##表示二級標題。

單星號 *代表斜體字體,雙星號 ** 代表加粗字體。

  • 放一個*在前後,表斜體字體

斜體字體

  • 放兩個*在前後,表表加粗字體

雙星號

十個超級好用的R語言程式設計技巧,一般人絕不知道!

https://ithelp.ithome.com.tw/articles/10213927

apply家族函數介紹

https://sodocumentation.net/zh-tw/r/topic/3567/-%E9%81%A9%E7%94%A8%E5%87%BD%E6%95%B8%E6%97%8F-%E5%87%BD%E6%95%B8-

rgb()函數中參數alpha是用來設置透明度的,對於特別密集的散點圖很常用。

colors() 顏色抓取 http://www3.nccu.edu.tw/~99354011/R%20commands%2811.09.13%29.pdf

R函數 pie()

pie(…..radius,clockwise…)
https://kknews.cc/zh-tw/code/grvxg2l.html

R函數 sub()與gsub()函數的區別 代換的功能

https://blog.csdn.net/weixin_34341229/article/details/85978263?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522158732931319724845052216%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=158732931319724845052216&biz_id=0&utm_source=distribute.pc_search_result.none-task-blog-2blogfirst_rank_v2~rank_v25-3

R函數-unique() 刪除重複元素或刪除重複(矩陣)行

https://blog.csdn.net/happywlg123/article/details/84107375

R函數-sql(),rep() https://blog.csdn.net/lili_wuwu/article/details/51907715 https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/rep

mai 設置圖形空白邊界,mai =c(bottom, left, top, right),單位為英寸。 缺省為mai= c(1.02,0.82,0.82,0.42)。 mar 設置圖形空白邊界行數,mar = c(bottom, left, top, right)。缺省為mar = c(5.1,4.1,4.1,2.1)。 http://newtomaso.blogspot.com/2015/02/par-in-r-rpar.html

繪圖參考網址 https://kknews.cc/code/9oemv35.html https://www.rdocumentation.org/packages/graphics/versions/3.6.2/topics/par https://kknews.cc/code/zbbn6op.html https://kknews.cc/zh-tw/news/mpnzp99.html # bg op

#畫圖,bg控制顏色 op <- par(bg=“red”)

常態分布 Normal Distribution (簡寫為 norm) 而言,就有 dnorm, pnorm, qnorm, rnorm 等四個函數