Thanks, irgrahamuk
But what I desired was a bit more complex.
Suppose, using iris dataset, that I want the rowsum of Sepal.Length, Sepal.Width, and Petal.Length only if Petal.Width is between 0,8 and 1.2.
I applied the next code
zax=datasets::iris
list_g <- c("Petal.Length","Sepal.Width","Petal.Length")
zax$rowsum_result2=ifelse((zax$Petal.Length >=0.8 & zax$Petal.Length <=1.2), rowSums(zax[,list_g]),NA)
table(zax$rowsum_result2)
It seems to work. However, my doubt now is how can you do the same process using the sapply/apply command and not a conditional. Or, in other word, how to include the exception rule in a sapply/apply order.
Again, thanks for your time and interest.