Home » R Language

Maximum of 3 numbers in R language using user-defined function

Here, we are creating a user-defined function in R programming language to find the maximum of 3 numbers.
Submitted by Akash Kumar, on November 08, 2018

Aim: To create user-defined function in R to find maximum of three numbers.

Syntax:

To create function in R following syntax is used:

    Function-name=function(parameter)
    {
        #body of function
    }

Where,

  • Function-name is the name of user-defined function.
  • function is the keyword which is used in R to create function
  • #body of function basically defines the property of function.

Code:

    maximum=function(a,b,c)
    {
	    max=a;
	    if(b>max)
		    max=b;
	    if(c>max)
		    max=c;
	    return(max);
    }

Output

find max of 3 numbers in R language

Hence, we successfully created function in R which will calculate maximum among three numbers in R.





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.