当前位置:网站首页>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
边栏推荐
- Brief introduction to XHR - basic use of XHR
- Xray and Burp linked Mining
- HackMyvm靶机系列(5)-warez
- Relationship between hashcode() and equals()
- Middleware vulnerability recurrence Apache
- Attach the simplified sample database to the SQLSERVER database instance
- canvas基础2 - arc - 画弧线
- Experiment 7 use of common classes
- xray与burp联动 挖掘
- It's never too late to start. The tramp transformation programmer has an annual salary of more than 700000 yuan
猜你喜欢
Hackmyvm target series (6) -videoclub
Hackmyvm target series (4) -vulny
1. First knowledge of C language (1)
Reinforcement learning series (I): basic principles and concepts
Harmonyos JS demo application development
Callback function ----------- callback
Xray and burp linkage mining
HackMyvm靶机系列(4)-vulny
How to understand the difference between technical thinking and business thinking in Bi?
2. First knowledge of C language (2)
随机推荐
The difference between abstract classes and interfaces
About the parental delegation mechanism and the process of class loading
附加简化版示例数据库到SqlServer数据库实例中
7-3 construction hash table (PTA program design)
Beautified table style
Package bedding of components
SQL注入
Difference and understanding between detected and non detected anomalies
Relationship between hashcode() and equals()
Detailed explanation of three ways of HTTP caching
Experiment 8 exception handling
Miscellaneous talk on May 14
1. First knowledge of C language (1)
7-1 输出2到n之间的全部素数(PTA程序设计)
"Gold, silver and four" job hopping needs to be cautious. Can an article solve the interview?
7-4 hash table search (PTA program design)
7-7 7003 组合锁(PTA程序设计)
强化學習基礎記錄
7-8 7104 Joseph problem (PTA program design)
UGUI—Text