Andrew Yee
2007-Jul-09 13:12 UTC
[R] using the function unique(), but asking it to ignore a column of a data.frame
Take for example the following data.frame: a<-c(1,1,5) b<-c(3,2,3) c<-c(5,1,5) sample.data.frame<-data.frame(a=a,b=b,c=c) I'd like to be able to use unique(sample.data.frame), but have unique() ignore column a when determining the unique elements. However, I figured that this would be setting for incomparables=, but it appears that this funcationality hasn't been incorporated. Is there a work around for this, i.e. to be able to get unique to only look at selected columns of a data frame? Thanks, Andrew
hadley wickham
2007-Jul-09 13:28 UTC
[R] using the function unique(), but asking it to ignore a column of a data.frame
On 7/9/07, Andrew Yee <yee at post.harvard.edu> wrote:> Take for example the following data.frame: > > a<-c(1,1,5) > b<-c(3,2,3) > c<-c(5,1,5) > sample.data.frame<-data.frame(a=a,b=b,c=c) > > I'd like to be able to use unique(sample.data.frame), but have > unique() ignore column a when determining the unique elements. > > However, I figured that this would be setting for incomparables=, but > it appears that this funcationality hasn't been incorporated. Is > there a work around for this, i.e. to be able to get unique to only > look at selected columns of a data frame?unique(df[,c("a","c")]) ? Hadley