0

I want to Find the no of students who get >500 and >300-<400 and <400 of various subjects in R.

My Data set: English : int 430 430 430 430 430 430 430 430 430 430 ... Quantitative: int 605 575 325 575 605 120 475 475 785 460 ... Logical : int 555 510 470 460 505 310 435 360 530 435 ... Coding : int 672 531 477 410 660 692 436 635 221 314 ... Pyschometric: int 224 426 616 708 302 595 328 346 760 775 ... Input IMAGE

Required output in R should be: Values.............: Eng Qua Log Eng% Quant% Logical% 600 & <799: 114 182 271 10 16 10 2 400 & <599: 322 283 393 27 24 27 34 200 & <401: 496 333 609 42 42 42 53 100 & <200: 241 361 138 21 21 31 12 output Image

Please provide me the commands in R programming to do so that

Daniel Fischer
  • 3,280
  • 1
  • 18
  • 29
  • 2
    You can try `lapply(df1, function(x) table(cut(x, breaks = c(100, 500, 600, Inf)))` – akrun Jan 07 '17 at 05:14
  • 4
    Please do not post data as images! I suggest you read about [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and [minimal](http://stackoverflow.com/help/mcve) examples. Then please come back here and edit your question, pasting the output of something like `dput(head(mydataset, n = 10))` (so we can we your data), and pasting what the R data.frame should look like once we have manipulated your data. – r2evans Jan 07 '17 at 05:38
  • Can u please more elaborate your answer – Prem Kandagattla Jan 07 '17 at 06:17
  • 1
    r2evans comment is not an answer but hints to you how to ask the question in a way we can work on it. It would be helpful and appropriate if you provide us with the code you have tried so far. – vaettchen Jan 07 '17 at 06:37

1 Answers1

0

As answered by Akrun, you can use lapply to count each range

subj1 <- sample(1:600, 200, replace=F)
subj2 <- sample(1:600, 200, replace=F)
subj3 <- sample(1:600, 200, replace=F)

df <- data.frame(subj1, subj2, subj3)

df.2 <- lapply(df, function(x) table(cut(x, breaks = c(0, 300, 400, 500, Inf))))
output <- matrix(unlist(df.2), ncol = 4, byrow = TRUE)

colnames(output) <- c("0-300","301-400", "401-500", ">500")
rownames(output) <- c("subj1","subj2", "subj3")

output

> output
      0-300 301-400 401-500 >500
subj1    93      35      31   41
subj2    89      35      44   32
subj3    92      40      33   35
Hardik Gupta
  • 4,700
  • 9
  • 41
  • 83