当前位置:网站首页>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
边栏推荐
- SQL注入
- [err] 1055 - expression 1 of order by clause is not in group by clause MySQL
- Attach the simplified sample database to the SQLSERVER database instance
- Zatan 0516
- 实验九 输入输出流(节选)
- Implementation of count (*) in MySQL
- Meituan dynamic thread pool practice ideas, open source
- Inaki Ading
- Implementation principle of automatic capacity expansion mechanism of ArrayList
- 7-3 construction hash table (PTA program design)
猜你喜欢
随机推荐
Brief introduction to XHR - basic use of XHR
Strengthen basic learning records
Hackmyvm target series (7) -tron
Experiment 4 array
Using spacedesk to realize any device in the LAN as a computer expansion screen
网络基础详解
Experiment 6 inheritance and polymorphism
7-8 7104 Joseph problem (PTA program design)
.Xmind文件如何上传金山文档共享在线编辑?
Inaki Ading
Matlab opens M file garbled solution
7-4 hash table search (PTA program design)
[dark horse morning post] Shanghai Municipal Bureau of supervision responded that Zhong Xue had a high fever and did not melt; Michael admitted that two batches of pure milk were unqualified; Wechat i
Harmonyos JS demo application development
MATLAB打开.m文件乱码解决办法
Experiment 9 input and output stream (excerpt)
Canvas foundation 1 - draw a straight line (easy to understand)
canvas基础1 - 画直线(通俗易懂)
Yugu p1012 spelling +p1019 word Solitaire (string)
【黑马早报】上海市监局回应钟薛高烧不化;麦趣尔承认两批次纯牛奶不合格;微信内测一个手机可注册俩号;度小满回应存款变理财产品...