I am new to R and I am trying to create simple UDFs in R. Every time I try to create one, I get the error "
Error: unexpected symbol in:".
Not sure where I am going wrong. Here are a few examples of the functions that I was creating
Function 1
addPercent <- function(x) {
percent <- round (x *100, digits = 1) result<- paste(percent, "%", sep="") return(result)
}
Function 2
avg<- function(x) { s <- sum(x) n <- length(x) s/n }
Would really appreciate any kind of help to solve this minor issue. Thank you much in advance
;to separate multiple commands or use new lines. Soavgshould readavg <- function(x) { s <- sum(x); n <- length(x); s/n }