For example,
- I have a variable (column name) = "mode" in a sample data frame.
- And there is a built-in function with R with its name "mode"
How do I tell my script to get values from the first one (1) and not on second one (2)?
Can you give an example where the column name mode causes a problem? Here are a couple of examples where there is no problem.
DF <- data.frame(mode = 1:4)
DF$mode
[1] 1 2 3 4
library(dplyr)
DF |> mutate(mode2 = mode * 2)
mode mode2
1 1 2
2 2 4
3 3 6
4 4 8
When you select() the columns, you do not include class, so when you try to filter() there is no class column and that causes the error. Compare the two version below
library(tidyverse)
#This throws an error
mpg |> select(manufacturer,model, cty, hwy) |>
filter(manufacturer == "volkswagen") |>
filter(class == "compact")
#No error
mpg |> select(manufacturer,model, cty, hwy, class) |>
filter(manufacturer == "volkswagen") |>
filter(class == "compact")
Thank you! I understand now.