-4

I have the following output and would like to insert a column if net.results$net output equal to 0 if the output if <0.5 and 1 if >0.5 but <1.0. Basically rounding up or down.

How do I go about doing in this in a loop ? Can I insert this column using data.frame below , just in between the predicted and the test set columns ?

Assume I don't know the number of rows that net.results$net.result has.

Thank you for your help.

data.frame(net.results$net.result,diabTest$class)

           predicted col            Test set col

net.results.net.result diabTest.class
4             0.2900909633              0
7             0.2900909633              1
10            0.4912509122              1
12            0.4912509122              1
19            0.2900909633              0
21            0.2900909633              0
23            0.4912509122              1
26            0.2900909633              1
27            0.4912509122              1
33            0.2900909633              0
user4745212
  • 51
  • 1
  • 3
  • 11

1 Answers1

0

As the commenters have pointed out. This will not work for some situations, but based on the appearance of the data, this should produce the output desired.

df$rounded <- round(df$net.results.net.result,0)

Here are a few test values to see what the function does for different numbers. Read the round help page for more info.

round(0.2900909633,0)
[1] 0
round(0.51, 0)
[1] 1

You can help everyone by supplying a reproducible example, doing research, and explaining approaches that you've tried.

Pierre L
  • 28,203
  • 6
  • 47
  • 69
  • Thank you. It works . the code is some neural network which I can't really post. – user4745212 Apr 25 '15 at 17:27
  • 1
    reproducible could mean something as simple as making a dummy table with 10 random decimals in one column and 10 random 1's and 0's in another. If you want to continue getting help, you have to supply more information, not necessarily your exact data source. – Pierre L Apr 25 '15 at 17:47