Create a conditional to print the media and standard deviation on the screen

Asked

Viewed 28 times

0

I would like to create a conditional for average and standard deviation of a given group. I usually do this by dividing subsets, but as there are many categories I thought would be better with a parole. I put together a code to test. It runs but does not print the results on the screen.

if( males[,2]<=22.11 && 18<=males) {
  print(mean(estatura))
  print(mean(CVF))
  print(mean(VEF1))
}
  • Can you please, edit the question with the departure of dput(males) or, if the base is too large, dput(head(males, 20))? And tell how groups are defined.

1 answer

0

If I understood, you can make a cutout of the bank, with the lines that obey the condition and take average, Sv-pad...

Consider below the d.orig the original data:

condicao <- males[, 2] >= 18 & males[, 2] <= 22.11 
d.cond <- d.orig[condicao, ]
mean(d.cond$estatura)

You can use the dplyr::filter

library(dplyr)
d.cond <- d.orig %>%
  filter(variavel1 >= 18 & variavel2 <= 22.11) %>% 
  summarise(media = mean(variavel3))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.