Split based on median

Hello, I am trying to split my dataframe into two different ones. I would like to create one with "high score" and the other with "low score". The cutoff value should be based one the median of a continuous variable.

Can someone help me with the code?


data_high <- split(data,data$variable)

but how can I define the cutoff value?

Thanks in advance.

Here are a couple of ways to split the data frame using data I invented.

#Make a data frame
DF <-  data.frame(Name = LETTERS[1:20], Value = rnorm(20))

#Calculate median value
MedianValue <- median(DF$Value)

#Method 1
HighDF <- DF[DF$Value > MedianValue,]
LowDF <- DF[DF$Value <= MedianValue,]

HighDF <- filter(DF, Value <= MedianValue)
LowDF <- filter(DF, Value > MedianValue)

1 Like

Thanks a lot!! Actually easier than expected...saved a lot of time.

This topic was automatically closed 21 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.