Greetings !
Is it possible to do a selection in RStudio ? Like if I have a column year going from 1990 to 2017, is it possible to do the mean of the observations in 1990 only ?
Kind regards
simco
Greetings !
Is it possible to do a selection in RStudio ? Like if I have a column year going from 1990 to 2017, is it possible to do the mean of the observations in 1990 only ?
Kind regards
simco
Welcome to the community!
It is indeed possible in R
, which is the programming language, of which RStudio
is an IDE.
If you have a column named year
in a data frame df
, and you want mean of the column obs
, then you can do mean(x = df$obs[df$year == 1990])
. Obviously, there are many other ways to do the same.
Thank you very much for your quick answer !
And to add another condition ? Like here I have the method of cultivation that can be either Organic or conventional ? So for example, if I want to calculate the mean of the surface of organic cultivation in 1990, I tried :
mean (a$Surface [a$Annee==1990,a$Methode=="Organic farming"])
But it doesn't work
To combine conditions, you'll need &
for intersection and |
for union. So, try with mean(a$Surface[a$Annee==1990 & a$Methode=="Organic farming"])
.
Perfect ! Thanks again ! Is the way I marked read alright ?
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.