index rows based on values from one column in r

In R, you can index rows based on values from one column using the subset() function. Here is an example:

# Create a data frame
df <- data.frame(ID = c(1, 2, 3, 4, 5),
                 Name = c("John", "Jane", "Mike", "Emily", "Chris"),
                 Age = c(25, 30, 35, 20, 28))

# Index rows based on values from the 'Age' column
subset(df, Age > 25)

251 chars
9 lines

In the above example, the subset() function is used to index rows where the 'Age' column value is greater than 25. This will return a new data frame with only the rows that meet the specified condition.

related categories

gistlibby LogSnag