How to write function in R

How to write function in R

There are many built-in functions in R which we use in different situations. But we may be fall in some situation when we may need to write our own customized function in R. Writing user defined function is not only required in different general programming languages but also required in different data analytics programming language or environment. If you want to be a good data scientist you have know how to write function in R. Here I will show you some basic to real lifeĀ  example of writing some function in R. Hope you will enjoy my example and you will be confident about function in R.

#defining the function
function_read_number <- function()
{
  r <- readline(prompt="Please, input a number:");
}

#input a number through the above function
n <- as.integer(function_read_number());

#after executing the above code run the below code to display the number
print(paste("You have entered:", n));

 

You are welcome to comment regarding our post. We will update our post according to your requirement if there any necessary or we will upload a new post regarding your requirement.

If the above example help you in any way, please share or recommend with your friends. If you are not with us at facebook, youtube you can like us our facebook page as well as subscribe our youtube channel today to get latest post from us.

Disclaimer: The R Foundation is the owner of R logo

Add a Comment