How to create two groups

Hello there,

I just started with Rstudio so bear with me :slight_smile:

My data looks like this:

Country Confirmed Deaths Recovered Date AverageTemperature AverageTemperatureUncertainty
1 Afghanistan 281 6 10 2013-08-01 26.031 0.347
2 Albania 304 17 89 2013-08-01 24.793 0.928
3 Algeria 1171 105 62 2013-08-01 33.234 0.798

I would like to compute the mean of the AverageTemperature column and label every value lower than the mean ''Low'' and every value higher than the mean ''High''.
Also, I'd like to do this by the Median as well.

I can't seem to find the solution while it doesnt look that hard to achieve..

Someone that knows a solution?

Thanks,
Jop

RStudio is just an IDE, and the underlying programming language is R.

If your data is in a data.frame named df, have you tried to do something like this?

df$TemperatureBasedLabels <- ifelse(df$AverageTemperature < mean(df$AverageTemperature), "Low", "High")

For median, replace mean function with median.

Awesome, this works for me! Thanks very much for your time!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.