To find the sum of rows in R based on a condition, we select only the rows that match the condition and then use the sum() function to add their values.
Method 1: Sum of Rows Based on a Single Condition
We calculate the sum of specific row values filtered by one logical condition.
Example: 1
team, captain, centuries: vectors used to define data
data.frame(): creates the data frame from vectors
df: name of the data frame
print(): displays the data frame or result
with(): applies expressions within a data frame context
sum(): calculates the total
[captain == 'dhoni']: filters rows where captain equals "dhoni"