Expt 2
Expt 2
ipynb - Colab
creating a dataframe
people
A data.frame: 5 × 3
name age child
Anne 28 FALSE
pete 30 TRUE
Frank 21 TRUE
Julie 39 FALSE
Cath 35 TRUE
people[c(3,5),c("name","age","child")]
A data.frame: 2 × 3
name age child
3 Frank 21 TRUE
5 Cath 35 TRUE
people[,"age"]
account_circle 28 · 30 · 21 · 39 · 35
people[1,]
A data.frame: 1 × 3
name age child
1 Anne 28 FALSE
people [1,1]
'Anne'
people [1,"name"]
'Anne'
people[1,"age"]
28
people
https://colab.research.google.com/drive/1tRQtGhxkhSS51uXZM9bptrlVhNgwKzgZ#printMode=true 1/3
5/8/24, 4:18 PM Implementation_and_use_of_data_frames_in_R.ipynb - Colab
A data.frame: 5 × 3
name age child
Anne 28 FALSE
pete 30 TRUE
Frank 21 TRUE
Julie 39 FALSE
Cath 35 TRUE
people
A data.frame: 5 × 4
name age child height
people
A data.frame: 5 × 5
name age child height weight
A data.frame: 5 × 6
name age child height weight address
https://colab.research.google.com/drive/1tRQtGhxkhSS51uXZM9bptrlVhNgwKzgZ#printMode=true 2/3
5/8/24, 4:18 PM Implementation_and_use_of_data_frames_in_R.ipynb - Colab
sam <- data.frame(name="sam", age = 32, child = FALSE, height = 180, weight = 80, address = "ponda")
sam
A data.frame: 1 × 6
name age child height weight address
rbind(people,sam)
1. rbind(people, sam)
2. rbind(deparse.level, ...)
3. stop("numbers of columns of arguments do not match")
Sorting by age
3·1·2·5·4
28 · 30 · 21 · 39 · 35
people[ranks,]
A data.frame: 5 × 5
name age child height weight
sort by height
2·5·1·3·4
163 · 177 · 163 · 162 · 175
A data.frame: 5 × 5
name age child height weight
https://colab.research.google.com/drive/1tRQtGhxkhSS51uXZM9bptrlVhNgwKzgZ#printMode=true 3/3