Well, testing would have been wise.. The last variable in the sample
dataframe had 5 elements and the use "negation" of a character vector
is not proper.
> df[ , -c("a","d")]
Error in -c("a", "d") : invalid argument to unary operator
So if you limit yourself to negative indexing of numeric r
On Thu, Jan 8, 2009 at 5:52 AM, Christian Kamenik <
christian.kame...@giub.unibe.ch> wrote:
>
> 'Apply' is a great thing for running functions on rows or columns of a
> matrix:
>
> X <- rnorm(20, mean = 0, sd = 1)
> dim(X) <- c(5,4)
> apply(X,2,sum)
>
> Is there a way to use apply for excluding ro
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
Dear all,
'Apply' is a great thing for running functions on rows or columns of a
matrix:
X <- rnorm(20, mean = 0, sd = 1)
dim(X) <- c(5,4)
apply(X,2,sum)
Is there a way to use apply for excluding rows or columns from a matrix
to run functions on the remaining rows or columns? I know, I could
4 matches
Mail list logo