stuti sharma
stuti sharma

Reputation: 51

select command not working in R even after installing the library dplyr

Error message : could not find function "select"

After installing the package which contains the select function for R, this error isn't expected but still i am getting this error. I want to select a particular column of the dataset but the dollar sign operator is also not working.

Upvotes: 2

Views: 26066

Answers (3)

cmoshe
cmoshe

Reputation: 369

There are various ways you can try to solve this problem.

  1. Restart the R session with ctrl + shift + F10
  2. You can use dplyr::select() if that's the select function you want

Upvotes: 0

Matthew Acre
Matthew Acre

Reputation: 31

@THATguy nailed it! That will solve your problems. The cause of this error is often due to multiple libraries with the same function. In this case specifically, the function "select" exists in the package 'dplyr' and 'MASS'. If you type in select in your code it's likely going to pull the MASS library, and if your intention is select only certain columns out of a data frame then, you want to the select from 'dplyr'. For example:

df <- read.csv("df.csv") %>% #bring in the data frame
      dplyr::select(-x, -y, -z) # remove the x, y, and z columns from the data frame

Or if you want to keep certain columns then drop the '-' in front of the variable.

Upvotes: 3

THATguy
THATguy

Reputation: 312

I think I've had this problem as well and I'm not sure what causes it. However, I can usually solve the problem by specifying the package before the command as in the code below.

dplyr::select()

Hope this helps.

Upvotes: 9

Related Questions