1

I am trying to remove duplicates

laa <-subset(la,select =c(PermID))

class(laa)

laa1<-laa[!duplicated(laa$userPermID), ]

class(laa1)

when i ran first two lines the class command is showing it as data.frame but after running the duplicate command it is converting into factor automatically. Is there any specific reason. Because iam not able to see it in dataframe

1
  • Most probably, it was already a factor when it was still in the data.frame. Use str instead of class for some more info Commented May 30, 2016 at 6:52

1 Answer 1

1

As we are only selecting the 'PermID' in the first step, the default option while subsetting the rows with [ having a single column data.frame would be drop=TRUE resulting in a vector instead of a data.frame. Assuming that 'PermID' is a factor column, the class of the vector will be factor. To avoid that, use drop=FALSE.

laa1 <- laa[!duplicated(laa$userPermID), , drop=FALSE]

The class(laa1) would be data.frame.


If we look at the documentation ?"[", the default usage is

x[i, j, ... , drop = TRUE]

drop: For matrices and arrays. If TRUE the result is coerced to the lowest possible dimension (see the examples). This only works for extracting elements, not for the replacement. See drop for further details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.