first time user here! I'm just learning R and have what I hope is a simple question. I have an array of numbers, nums, and I would to ensure no number is greater than one. I'm trying to do
myfct <- function(x) {
if ( x > 1.0 ) x = 1.0
return(x)
}
apply(nums, 1, myfct)
But I then get this error
Error in apply(nums, 1, myfct) :
dim(X) must have a positive length
What am I doing wrong and is there a better way to do it? Thanks!