markdown基本操作

1、生成一个有序列表,形如:

  1. A

    1.1. A1

     1.11. a1
     1.12. a2
    

    1.2. A2

  2. B

    -无序列表1

    -无序列表2

2、生成一个表格

表头一 表头二 表头三
A B C
甲 乙 丙

3、生成数学公式 $$loss=\sum_{i=1}^{n}(y_i - \hat{y_i})^2$$

1.有序列表

  1. A

    1.1. A1

     1.11. a1
     1.12. a2
    

    1.2. A2

  2. B

    -无序列表1

    -无序列表2

2、生成一个表格,表头内容居中,且表头字体为斜粗体

表头一 表头二 表头三
A B C
甲 乙 丙

3、生成数学公式,形如 $$loss=\sum_{i=1}^{n}(y_i - \hat{y_i})^2$$

R语言入门

1、对1.2547四舍五入保留两位小数,判断其结果与1.25是否相等

2、计算2021/9/9与2020/9/9相差天数,并用cat()函数将结果保存在"exp1.txt"文件中

3、将Statistical Software With R转换成Statistical SOFTWARE With R

4、将c("22万", "30万", "50万", "120万", "11万")转换为c("220000", "300000", "500000", "120000", "110000"),并计算平均值

5、用paste函数将a、b、c,1、2、3两个列表用"."对应连接(最终结果:"a.1 b.2 c.3")

6、用"的"作为分隔符号拆分"实用的统计的软件"

7、从c("1","12","1a3","1234")中查找"a"出现的位置,并将"a"替换成空格

8、判断2021/9/10是星期几

9、将c("C","B","A")按字母表顺序转化为有序因子

In [2]:
round(1.2547,2)
identical(round(1.2547,2),1.25)

difftime(as.Date("2021-9-9"),as.Date("2020-9-9"),units = 'days')
cat(difftime(as.Date("2021-9-9"),as.Date("2020-9-9"),units = 'days'),file = "exp1.txt")

phrase <- "Statistical Software With R"
substr(phrase,13,20) = toupper(substr(phrase,13,20))
phrase

salary <- c("22万", "30万", "50万", "120万", "11万")
salary0 <- gsub("万","0000",salary)
salary0
mean(as.numeric(salary0))

paste(c("a","b","c"),1:3,sep=".",collapse = " ")

strsplit("实用的统计的软件",split = "的")[[1]]

grep("a",c("1","12","1a3","1234"))
gsub("a"," ",c("1","12","1a3","1234"))

weekdays(as.Date("2021/9/10"))

factor(c("C","B","A"),ordered = TRUE,levels = LETTERS[1:3])
1.25
TRUE
Time difference of 365 days
'Statistical SOFTWARE With R'
  1. '220000'
  2. '300000'
  3. '500000'
  4. '1200000'
  5. '110000'
466000
'a.1 b.2 c.3'
  1. '实用'
  2. '统计'
  3. '软件'
3
  1. '1'
  2. '12'
  3. '1 3'
  4. '1234'
'星期五'
  1. C
  2. B
  3. A
Levels:
  1. 'A'
  2. 'B'
  3. 'C'

数据结构

1、创建包含7,8,-6,10,88,45的数值型向量,用x表示

2、提取x中大于等于10且小于50的元素并显示,并返回对应的下标

3、创建包含"男", "女","男", "女","男","女","女"的因子型向量,用y表示,并用name()函数把"男"记为M,"女"记为F,最后用table()函数汇总结果

4、利用标准正态分布随机数(随机数种子设为0),生成2个5行5列的矩阵A和B,分别求两个矩阵的逆,并做转置,再分别按照行和列合并两个矩阵A,B

5、计算A和B矩阵的内积,寻找A矩阵中的最小元素,并返回其位置

In [6]:
x <- c(7,8,-6,10,88,45)
x

x[x>=10 & x<50]
which(x>=10 & x<50)

gender <- c("男","女","男","女","男","女","女")
y <- factor(gender,levels=c("女","男"))
y
code <- c("F","M")
names(code) <- c("女","男")
code[y]
table(code[y])

set.seed(0)
A <- matrix(rnorm(25),nrow = 5,ncol = 5)
A
B <- matrix(rnorm(25),nrow = 5,ncol = 5)
B
solve(A)
solve(B)
t(A)
t(B)
rbind(A,B)
cbind(A,B)

crossprod(A,B)
min(A)
which(A == min(A,na.rm = TRUE),arr.ind = TRUE)
  1. 7
  2. 8
  3. -6
  4. 10
  5. 88
  6. 45
  1. 10
  2. 45
  1. 4
  2. 6
  1. 男
  2. 女
  3. 男
  4. 女
  5. 男
  6. 女
  7. 女
Levels:
  1. '女'
  2. '男'
男
'M'
女
'F'
男
'M'
女
'F'
男
'M'
女
'F'
女
'F'
F M 
4 3 
A matrix: 5 × 5 of type dbl
1.2629543-1.539950042 0.7635935-0.4115108-0.22426789
-0.3262334-0.928567035-0.7990092 0.2522234 0.37739565
1.3297993-0.294720447-1.1476570-0.8919211 0.13333636
1.2724293-0.005767173-0.2894616 0.4356833 0.80418951
0.4146414 2.404653389-0.2992151-1.2375384-0.05710677
A matrix: 5 × 5 of type dbl
0.50360797-0.2357066 1.1519118 1.7579031-1.0655906
1.08576936-0.5428883 0.9921604 0.5607461-1.5637821
-0.69095384-0.4333103-0.4295131-0.4527840 1.1565370
-1.28459935-0.6494716 1.2383041-0.8320433 0.8320471
0.04672617 0.7267507-0.2793463-1.1665705-0.2273287
A matrix: 5 × 5 of type dbl
-0.2325407-1.0146556 0.603052690.2782251-0.466154641
-0.3641468-0.5279929 0.094982910.1298220-0.009274745
0.7584265 0.5256009-0.922848310.1587565 0.575936572
-1.0239124-1.6160245 0.686227760.2742001-1.194989031
1.1930377 2.6663475-1.657446680.7127877 1.592216262
A matrix: 5 × 5 of type dbl
-290.11519-51.854131-458.6120676.027810-338.32298
-99.39574-18.760681-158.6615126.298143-115.97230
-163.71338-29.611884-259.8097743.581346-191.17650
17.22695 2.672131 26.58352-4.583123 19.33741
-264.61960-47.959384-418.6502869.665354-309.00412
A matrix: 5 × 5 of type dbl
1.2629543-0.3262334 1.3297993 1.272429321 0.41464143
-1.5399500-0.9285670-0.2947204-0.005767173 2.40465339
0.7635935-0.7990092-1.1476570-0.289461574-0.29921512
-0.4115108 0.2522234-0.8919211 0.435683299-1.23753842
-0.2242679 0.3773956 0.1333364 0.804189510-0.05710677
A matrix: 5 × 5 of type dbl
0.5036080 1.0857694-0.6909538-1.2845994 0.04672617
-0.2357066-0.5428883-0.4333103-0.6494716 0.72675075
1.1519118 0.9921604-0.4295131 1.2383041-0.27934628
1.7579031 0.5607461-0.4527840-0.8320433-1.16657055
-1.0655906-1.5637821 1.1565370 0.8320471-0.22732869
A matrix: 10 × 5 of type dbl
1.26295428-1.539950042 0.7635935-0.4115108-0.22426789
-0.32623336-0.928567035-0.7990092 0.2522234 0.37739565
1.32979926-0.294720447-1.1476570-0.8919211 0.13333636
1.27242932-0.005767173-0.2894616 0.4356833 0.80418951
0.41464143 2.404653389-0.2992151-1.2375384-0.05710677
0.50360797-0.235706556 1.1519118 1.7579031-1.06559058
1.08576936-0.542888255 0.9921604 0.5607461-1.56378205
-0.69095384-0.433310317-0.4295131-0.4527840 1.15653700
-1.28459935-0.649471647 1.2383041-0.8320433 0.83204713
0.04672617 0.726750747-0.2793463-1.1665705-0.22732869
A matrix: 5 × 10 of type dbl
1.2629543-1.539950042 0.7635935-0.4115108-0.22426789 0.50360797-0.2357066 1.1519118 1.7579031-1.0655906
-0.3262334-0.928567035-0.7990092 0.2522234 0.37739565 1.08576936-0.5428883 0.9921604 0.5607461-1.5637821
1.3297993-0.294720447-1.1476570-0.8919211 0.13333636-0.69095384-0.4333103-0.4295131-0.4527840 1.1565370
1.2724293-0.005767173-0.2894616 0.4356833 0.80418951-1.28459935-0.6494716 1.2383041-0.8320433 0.8320471
0.4146414 2.404653389-0.2992151-1.2375384-0.05710677 0.04672617 0.7267507-0.2793463-1.1665705-0.2273287
A matrix: 5 × 5 of type dbl
-2.25219753-1.2218599 2.0197958-0.1073194 1.6667890
-1.46033378 2.7461191-3.2474602-5.8947279 2.2007324
0.66785098 0.7216226 0.3049239 2.0038228-1.0643350
0.06538877-0.8358006 1.0445239 0.9030532-0.3436232
-0.83103744-0.7735989 1.0706142-0.8454921 0.4851272
-1.53995004190371
A matrix: 1 × 2 of type int
rowcol
12