How do I go about doing Median-Splits in R? I have a data set, [1:130], from SPSS with 7 different subscales that I need to do a proper median split on. With 2 being above median, and 1 being below median. I've been trying to figure out how to do it with R as I do not have immediate access to SPSS but nothing I find works. Can anyone give me any tips on how to got about doing this?
I am trying to use a median-split, to record data as high(2) or low(1), in order to use independent t tests , to test for significance.
I attempted to use the code found here:How to do median splits within factor levels in R?
but the results will not allow me to use them in a t test.
Applicable code:
alldata<- data.frame(scoreddata, subscaledata)
alldatascores<- c(subscaledata$scores, psyo372scored$nbis_tot, psyo372scored$nsss_tot, psyo372scored$npumps_a)
alldatalabels<-gl(10, 130, labels = c("nsss_dis", "nsss_bor", "nsss_thr", "nsss_exp", "nbis_nonplanning", "nbis_attentional", "nbis_motor", "nbis_tot", "nsss_tot", "npumps_a"))
alldata<- data.frame(alldatascores, alldatalabels)
alldata
ind.t.test<-t.test(alldata$npumps_a ~ alldata$nsss_dis, paired = FALSE)
ind.t.test
Resulting Error:
Error in model.frame.default(formula = alldata$npumps_a ~ alldata$nsss_dis) : invalid type (NULL) for variable 'alldata$npumps_a'