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?
e.g.
data_high <- split(data,data$variable)
but how can I define the cutoff value?
Thanks in advance.
FJCC
July 30, 2021, 4:41pm
2
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,]
#Method2
library(dplyr)
HighDF <- filter(DF, Value <= MedianValue)
LowDF <- filter(DF, Value > MedianValue)
1 Like
Thanks a lot!! Actually easier than expected...saved a lot of time.
system
Closed
August 20, 2021, 5:28pm
4
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.