0
votes

Columns: Area, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019

Rows: Woodbury County, Iowa | Plymouth County, Iowa | Webster County, Iowa | Black Hawk County, Iowa | Polk County, Iowa | Poweshiek County, Iowa | Linn County, Iowa | Dubuque County, Iowa | Scott County, Iowa | Rock Island County, Iowa

I don't necessarily need a completed answer for my question, a possible syntax would be sufficient. Any tips or advice on how to make this Process easier would be appreciated as well.

Thank you

Edit: I also need the data that is associated with the column/row

1
Please add data using dput and show the expected output for the same. Read about how to ask a good question and how to give a reproducible example.Ronak Shah

1 Answers

0
votes

You subset a dataframe by row name using the following format where df is a dataframe containing data, df[row, col] where row and col can be an index or a name (if named). You can subset by names using a vector of the names you want. You didn't really give an example, however the example below demonstrates this.

df <- data.frame(matrix(1, 10, 11))
rms <- c("Woodbury County, Iowa", "Plymouth County, Iowa", "Webster County, Iowa", 
     "Black Hawk County, Iowa", "Polk County, Iowa", "Poweshiek County, Iowa", 
     "Linn County, Iowa", "Dubuque County, Iowa", "Scott County, Iowa", 
     "Rock Island County, Iowa")
colnames(df) <- c('Area', 2010:2019)
rownames(df) <- rms
print(df)
df[c("Woodbury County, Iowa", "Plymouth County, Iowa", "Webster County, Iowa"), ]