Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

get maximum of 3 numbers and with this respective name

$
0
0

I am trying to get the maximum of 3 numbers along with its respective name assigned. But I get the maximum of the 3 numbers but the name assigned is not retrieved the last column as default. Please help.

maximum=function(a,b,c)
{
  max=a
  max1 = "aaa";
  if(b>max)
    max=b
    max1 = "bbb";
  if(c>max)
    max=c
  max1 = "ccc";
  print(paste(max1,max));
}

I get my error output as below:

> maximum(3,2,1)
[1] "ccc 3"

Expected output:

"aaa 3"

Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>