Answers for "custom function in r"

0

fuction in r

# Create a function to print squares of numbers in sequence.
new.function <- function(a) {
   for(i in 1:a) {
      b <- i^2
      print(b)
   }
}

# Call the function new.function supplying 6 as an argument.
new.function(6)
Posted by: Guest on April-29-2020
0

custom function in r

# create custom function 

addition <- function(x) { 
y <- x + 1			
print(y) 

} 


z <- 2
addition(z)  # call new function on variable, z
> 3    # R returns the new value created by function
Posted by: Guest on March-30-2021

Browse Popular Code Answers by Language