6 R objects solutions
6.1 df solution
6.1.1 Step 1
Create vectors for columns and row names:
<- c(2,4,6)
One <- c(6,12,18)
Three <- c(10,20,30)
Five <- c("Two", "Four", "Six") row_names
6.1.2 Step 2a
Create the data frame from vectors:
<- data.frame(One,Three,Five) df
Add row names:
row.names(df) <- row_names
6.1.3 Step 2b
Alternatively you can define the row names in the data.frame()
function
as an option:
<- data.frame(One,Three,Five, row.names = row_names) df
6.2 beach_df_2 solution
6.2.1 Step 1
Create vectors for columns and row names:
<- c(10,1,1,4)
Crab <- c(5,6,4,4)
Oystercatcher <- c(1,1,2,3)
Sandpiper <- c(3,3,7,4)
Starfish <- c("Formby","West Kirby","Crosby","New Brighton") row_names_2
6.2.2 Step 2a
Create the data frame from vectors:
<- data.frame(Crab,Oystercatcher,Sandpiper,Starfish) beach_df_2
Add row names:
row.names(beach_df_2) <- row_names_2
6.2.3 Step 2b
Alternatively you can define the row names in the data.frame()
function as an option:
<- data.frame(Crab,Oystercatcher,Sandpiper,Starfish, row.names = row_names_2) beach_df_2