[R] subsetting dataframe by rownames to be excluded
Alexy Khrabrov
deliverable at gmail.com
Sun Oct 12 05:58:03 CEST 2008
Is there a way to select a subset of a dataframe consisting of all
those rows with rownames *except* from a subset of rownames to be
excluded? Example:
> a <- data.frame(x=1:10,y=10:1)
> a <- a[order(a$y),] # to make rownames differ visually
> a[8,]
x y
3 3 8
> a["8",]
x y
8 8 3
> a[-8,]
x y
10 10 1
9 9 2
8 8 3
7 7 4
6 6 5
5 5 6
4 4 7
2 2 9
1 1 10
> a[-"8",]
Error in -"8" : invalid argument to unary operator
-- is there a similar exclusion operator or simple way? So far the
best I can do is
> a[setdiff(rownames(a),"8"),]
x y
10 10 1
9 9 2
7 7 4
6 6 5
5 5 6
4 4 7
3 3 8
2 2 9
1 1 10
Cheers,
Alexy
More information about the R-help
mailing list