R- Language - Is there a way to call a variable inside data frame in cases wherein it has same syntax with a built-in function?

Viewed 45

For example,

  1. I have a variable (column name) = "mode" in a sample data frame.

enter image description here

  1. And there is a built-in function with R with its name "mode"

enter image description here

How do I tell my script to get values from the first one (1) and not on second one (2)?

My sample code:

mpg %>% 
 select("manufacturer", "model", "cty", "hwy") %>% 
 filter(manufacturer == "volkswagen") %>% 
 filter(mpg$class == "compact")
1 Answers

There are multiple way to do this in R. Where the name of your data frame is, "df":

df$mode

df[,"mode"]

df[,2]

These will all return values from the column and not from the built-in function.

Related