Skip to content

Instantly share code, notes, and snippets.

@neelabalan
Created November 3, 2023 12:31
Show Gist options
  • Save neelabalan/d839d255e87fe431f7a61d831a728176 to your computer and use it in GitHub Desktop.
Save neelabalan/d839d255e87fe431f7a61d831a728176 to your computer and use it in GitHub Desktop.
R functions - backup
add_numbers <- function(x, y) {
result <- x + y
return(result)
}
sumArray = function(arrayOfNumbers) {
result = 0
if(typeof(arrayOfNumbers)=="double") {
for(i in c(1:length(arrayOfNumbers))) {
result = result + arrayOfNumbers[i]
}
result
}
else
print("Warning: There is a non-numeric element in your array.")
}
HM = function(x) {
if(prod(x)==0) {
return (0)
} else {
length(x)/sum(1/x)
}
}
GM <- function(x) {
if (any(x <= 0)) {
stop("All numbers must be positive for the geometric mean.")
}
return (prod(x)^(1/length(x)))
}
PM = function(x, p) {
if (p ==0) {
prod(x)^{1/length(x)}
} else {
mean(x^p)^{1/p}
}
}
@rafe000000101010101010
Copy link

Which programing language it is?

@neelabalan
Copy link
Author

R

@rafe000000101010101010
Copy link

What is R? Is R is a any programing language?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment