-2

I am performing some prediction models. I have 2 binary columns , one with predicted values and the other one with the actual values.

Since the columns have few ones because it counts the number of people with cancer, i want to observe how many cases the model detected(how many real ones it predicted) and the percentage of sick persons correctly predicted.

Brief description of the data: the first column shows the real values and the seconde one shows the predicted values:

> predictedvsreal
         real prediction
39240       0    0
39241       0    0
39242       0    0
39243       1    0
39244       0    1
39245       0    0
39246       0    0
39247       0    0
39248       1    1
39249       0    0
39250       0    0
39251       0    0
39252       0    0

Thanks!

Martin
  • 41
  • 7
  • It's easier to help you if you provide some sort of [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and the desired output for that input. That way we can easily test possible solutions. – MrFlick Oct 07 '16 at 19:16
  • 1
    Some sample data and a demonstration of what you have tried would be very helpful [see here for more](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). In the meantime, you probably want to be looking at `table` – Mark Peterson Oct 07 '16 at 19:17
  • 1
    `with(your_data, table(your_first_column_name, your_second_column_name))` – Gregor Thomas Oct 07 '16 at 19:21
  • @Gregor you're spot on... that should be an answer, IMO – JD Long Oct 07 '16 at 19:22
  • What is the class of your data, not a data frame? If you post `dput(head(your_data))` everything will be much clearer... – Gregor Thomas Oct 07 '16 at 19:59
  • You keep editing and not addressing the problem. Please type (or copy/paste)`dput(head(predictedvsreal))` into your R console. Then copy the output which will look something like `structure(list(c(0, 0, ...` and paste it into your question. Format it as code. – Gregor Thomas Oct 07 '16 at 20:25

1 Answers1

1

Next time please include a reproducible example as it makes the question much better - both for letting people who answer have a concrete example to work with and to catch edge-cases, and for future readers to see a real example.

There are lots of good recommendations for how to create nice, minimal, reproducible examples at this link.

From what you describe, you want the table function, probably like this:

with(your_data, table(your_first_column_name, your_second_column_name))
Community
  • 1
  • 1
Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294