In case you are learning basic vector subsetting, here is an example.
data <- data.frame(
Id. = c(1, 2, 3, 4, 5),
Food. = c(23, 46, 99, 37, 12),
Sex = c(0, 1, 1, 0, 1)
)
# Generate logical vector checking for the condition
data$Sex == 1
#> [1] FALSE TRUE TRUE FALSE TRUE
# Select positions where the logical condition is TRUE
data$Food[data$Sex == 1]
#> [1] 46 99 12
# Calculate the mean only for the selected values
mean(data$Food[data$Sex == 1])
#> [1] 52.33333