Mastering Vectors and Data Frames for Data Manipulation
2024-02-01
something
something
c()
function.seq()
and rep()
.data.frame()
function.# Define the data
countries <- c("Comoros", "Kenya", "Madagascar", "Mauritius", "Mozambique",
"Réunion", "Seychelles", "Somalia", "South Africa", "Tanzania")
sst <- c(27.5, 28.2, 27.8, 26.9, 27.3, 26.7, 28.1, 28.4, 26.2, 27.9)
chl_a <- c(0.12, 0.15, 0.18, 0.20, 0.17, 0.19, 0.14, 0.11, 0.13, 0.16)
salinity <- c(35.2, 35.4, 35.3, 35.1, 35.2, 35.0, 35.3, 35.5, 35.1, 35.2)
surface_current <- c(0.5, 0.7, 0.6, 0.8, 0.7, 0.9, 0.6, 0.5, 0.8, 0.7)
wind_speed <- c(5.2, 5.8, 5.5, 6.0, 5.7, 6.2, 5.4, 5.1, 5.6, 5.3)
# Create the data frame
wio_data <- data.frame(
Country = countries,
SST = sst,
Chl_a = chl_a,
Salinity = salinity,
Surface_Current = surface_current,
Wind_Speed = wind_speed
)
# Print the data frame
print(wio_data)
Country SST Chl_a Salinity Surface_Current Wind_Speed
1 Comoros 27.5 0.12 35.2 0.5 5.2
2 Kenya 28.2 0.15 35.4 0.7 5.8
3 Madagascar 27.8 0.18 35.3 0.6 5.5
4 Mauritius 26.9 0.20 35.1 0.8 6.0
5 Mozambique 27.3 0.17 35.2 0.7 5.7
6 Réunion 26.7 0.19 35.0 0.9 6.2
7 Seychelles 28.1 0.14 35.3 0.6 5.4
8 Somalia 28.4 0.11 35.5 0.5 5.1
9 South Africa 26.2 0.13 35.1 0.8 5.6
10 Tanzania 27.9 0.16 35.2 0.7 5.3