I am having trouble subsetting my dataframe in R. I am trying to subset my data using a for loop (or any alternative) where it is separated by the 'TNC_DESCRI'
Table Example
but all I am getting is 'True', 'False'. I am using one of the landcover classes as an example but would like to do this process for all of the landcover classes in the table (thirty-three classes total):
for (Values in TS.df[3]){
for (j in TS.df[3]=='Sedge meadow complex') {
print(j)
}}
[1] FALSE [1] FALSE [1] FALSE [1] FALSE [1] FALSE [1] FALSE [1] FALSE [1] FALSE
After using dput(head(TS.df[1:10,]))
This is what my dataframe looks like:
`structure(list(**OBJECTID** = c(311L, 532L, 1307L, 1439L, 2726L,
2960L), **OBJECTID_12_13_14_15_16** = c(145L, 1L, 1L, 1L, 1L, 1L),
**TNC_DESCRI** = c("Water", "Spruce - fir / feathermoss forest",
"Spruce - fir / feathermoss forest", "Spruce - fir / feathermoss
forest",
"Spruce - fir / feathermoss forest", "Spruce - fir / feathermoss forest"
), **TNC_DESCRI_overlay** = c("Water", "Water", "Spruce - fir /
feathermoss forest",
"Spruce - fir / feathermoss forest", "Sedge meadow complex",
"Spruce - fir / feathermoss forest"), Conversion.1996.2017 = c("Water-
Water",
"Spruce - fir / feathermoss forest-Water", "Spruce - fir / feathermoss
forest-Spruce - fir / feathermoss forest",
"Spruce - fir / feathermoss forest-Spruce - fir / feathermoss forest",
"Spruce - fir / feathermoss forest-Sedge meadow complex",
"Spruce - fir / feathermoss forest-Spruce - fir / feathermoss forest"
), **Change.No.Change** = c("No Change", "Change", "No Change",
"No Change", "Change", "No Change"), **Edited_overlay** = c("",
"yes", "", "", "yes", ""), **Edit_Reason_overlay** = c("", "water not
land",
"", "", "wetland not upland", ""), **Map_Change_overlay** = c("",
"map", "", "", "map", ""), **Change_Reason_overlay** = c("",
"", "", "", "", ""), **Change_Reason_overlay.1** = c("No Change",
"No Change", "No Change", "No Change", "No Change", "No Change"
), **TCW** = c(NA, -494.21875, -494.21875, -494.21875, -494.21875,
-494.21875), **TCG** = c(NA, 1599.71875, 1599.71875, 1599.71875,
1599.71875, 1599.71875), **TCB** = c(NA, 2350.84375, 2350.84375,
2350.84375, 2350.84375, 2350.84375), **TCW_overlay** = c(NA,
NA, -341.84, -175.8, NA, -171), **TCG_overlay** = c(NA, NA, 1822.32,
1167.6, NA, 1600), **TCB_overlay** = c(NA, NA, 2299.68, 1594.6,
NA, 1939.5), **TCW_Difference** = c(NA, NA, 152.37875, 318.41875,
NA, 323.21875), **TCG_Difference** = c(NA, NA, 222.60125, -432.11875,
NA, 0.28125), **TCB_Difference ** = c(NA, NA, -51.1637500000002,
-756.24375, NA, -411.34375)), **row.names** = c(NA, 6L), class =
"data.frame")`
What I want to create is a subset for the landcover classes similar to the image below where only the rows with the same class are shown:
Sedge Meadow Complex Example