1

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'

Tim N.
  • 11
  • 4
  • Please provide a reproducible data set and your expected output for what you mean by median splits. Putting in codes you have tried would also help. – Adam Quek Oct 16 '17 at 03:05
  • 1
    Suggested links: [minimum, verifiable examples](https://stackoverflow.com/help/mcve) and [reproducible questions](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). (Though you just edited your question, one could argue that your example is quite far from "minimum" required to reproduce *just the problem*.) – r2evans Oct 16 '17 at 03:06
  • Yeah, sorry my first time posting here, still going through rules. I am not entirely sure where I went wrong though. I'll see if I can clean it up – Tim N. Oct 16 '17 at 03:08

0 Answers0