当前位置:网站首页>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
边栏推荐
- Miscellaneous talk on May 14
- Hackmyvm target series (3) -visions
- The difference between abstract classes and interfaces
- [MySQL table structure and integrity constraint modification (Alter)]
- Experiment 8 exception handling
- XSS之冷门事件
- 7-14 错误票据(PTA程序设计)
- Applet Web Capture -fiddler
- HackMyvm靶机系列(6)-videoclub
- 网络基础详解
猜你喜欢
随机推荐
The difference between abstract classes and interfaces
Differences among fianl, finally, and finalize
Strengthen basic learning records
7-9 make house number 3.0 (PTA program design)
HackMyvm靶機系列(3)-visions
撲克牌遊戲程序——人機對抗
xray與burp聯動 挖掘
WEB漏洞-文件操作之文件包含漏洞
Implementation principle of automatic capacity expansion mechanism of ArrayList
Have you encountered ABA problems? Let's talk about the following in detail, how to avoid ABA problems
记一次api接口SQL注入实战
HackMyvm靶机系列(3)-visions
Read only error handling
[three paradigms of database] you can understand it at a glance
HackMyvm靶机系列(5)-warez
【educoder数据库实验 索引】
Canvas foundation 2 - arc - draw arc
JS several ways to judge whether an object is an array
Experiment 9 input and output stream (excerpt)
HackMyvm靶机系列(7)-Tron