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