当前位置:网站首页>List and data frame of R language experiment III
List and data frame of R language experiment III
2022-07-06 14:04:00 【Baa Baa_ ten million five hundred and thirty-eight thousand sev】
list
1、 establish
1.1 Create a list L1, Record the names of three students (A,B,C), Number (1,2,3), Math scores (80,90,95), Chinese achievement (75,95,80)
L1<-list(` full name `= c('A','B','C'),` Number `= c(1,2,3),` Math scores `=c(83,77,90),` Chinese achievement `=c(73,65,82))
L1

1.2 take L1 Component names are changed to English , Write it down as L2
L2 <- L1
names(L2) <- c('name','id','math','lit')
L2 
1.3 take L1 and L2 As L3 Two components of
L3 <- list(l1 = L1,l2 = L2)
L3
2、 Indexes
2.1 Try indexing in different ways L1 Data in the
L1$` full name `[1] # Check the first name
L1[1] # Look at the first component
L1[[1]][2] # Look at the second element of the first component 

2.2 A What is your math score
L1$` mathematics `[L1$` full name `=='A']
![]()
2.3 The math score is greater than 85 Who is the classmate of the score ?
L1$` full name `[L1$` Math scores `>85]
![]()
2.4 The average score exceeds 85 Who is the classmate of the score ?
L1$` full name `[(L1$` Math scores `+L1$` Chinese achievement `)/2>85]
![]()
3、 Characteristics and operation
3.1 list L1 There are several components in
length(L1)![]()
3.2 How many numerical data are stored in the list
is.numeric(L1[[1]])+is.numeric(L1[[2]])+is.numeric(L1[[3]])+is.numeric(L1[[4]])
![]()
3.3 take L1 and L2 Combine them into a new list and record it as L3
L3 <- c(L1,L2)
L3
Data frame
1、 establish
1.1 Create a data frame df1, Record the names of three students (A,B,C), Number (1,2,3), Math scores (80,90,95), Chinese achievement (75,95,80)
df1 <- data.frame(name = c('A','B','C'),id = c(1,2,3), math = c(80,90,95), chinese= c(75,95,80))
df1

1.2 Set the row name of the data frame to name
rownames(df1) <- df1$name
df1
2、 Indexes
2.1 Try indexing in different ways df1 Data in the
df1[1] # First column
df1[[3]] # The third column
df1$chinese #chinese Column

2.2 A What is your math score
df1$math[df1$name=='A'] ![]()
2.3 The math score is greater than 85 Who is the classmate of the score ?
df1$name[df1$math>85] ![]()
2.4 The average score exceeds 85 Who is the classmate of the score ?
df1$name[(df1$math+df1$chinese)/2>85] ![]()
3、 Characteristics and operation
3.1 Get the row name of the data frame
rownames(df1) ![]()
3.2 Get the number of rows and columns of the data frame
dms <- dim(df1)
dms
![]()
3.3 Create a data frame df3, Record the names of three students (A,B,C), English scores (85,80,95), take df3 Information and df1 The information of is merged into df5
df3 <- data.frame(name = c('A','B','C'),english= c(85,80,95))
df5 <- merge(df1,df3) # Merge by columns 
3.4 Create a data frame df4, Record the name of a classmate (D), Number 4, Math scores 80, Chinese achievement 95, English scores 85, take df4 Information and df5 The information of is merged into df6
df4 <- data.frame(name = 'D', id = 4, math = 80, chinese = 95, english = 85)
df6 <- rbind(df5,df4) # Merge by line
df6 
边栏推荐
猜你喜欢

Differences among fianl, finally, and finalize

Safe driving skills on ice and snow roads

深度强化文献阅读系列(一):Courier routing and assignment for food delivery service using reinforcement learning

Tencent map circle

浅谈漏洞发现思路

网络层—简单的arp断网

【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...

Xray and Burp linked Mining

Meituan dynamic thread pool practice ideas, open source

Programme de jeu de cartes - confrontation homme - machine
随机推荐
简述xhr -xhr的基本使用
7-11 mechanic mustadio (PTA program design)
内网渗透之内网信息收集(一)
Detailed explanation of three ways of HTTP caching
7-15 h0161. 求最大公约数和最小公倍数(PTA程序设计)
7-6 local minimum of matrix (PTA program design)
Callback function ----------- callback
Difference and understanding between detected and non detected anomalies
7-8 7104 约瑟夫问题(PTA程序设计)
Strengthen basic learning records
XSS之冷门事件
Poker game program - man machine confrontation
Get started with typescript
Build domain environment (win)
内网渗透之内网信息收集(五)
The difference between overloading and rewriting
7-7 7003 combination lock (PTA program design)
A piece of music composed by buzzer (Chengdu)
实验五 类和对象
Beautified table style