Skip to content
Prev 166372 / 398503 Next

Excluding data with apply

Using indexing and putting a minus sign in front of a vector of column  
names that you want to exclude would be a typical approach:

df <- data.frame(a=LETTERS[1:4], b= rnorm(4), c=rnorm(4), d=  
letters[5:9])

apply(df[ , -c("a","d")], 2, sum)

(Pretty sure this will run properly but don't have R up an runnign to  
test it.)