Fixing a Multiple Warning "Unknown Column"

Unknown column in 'field list' error on MySQL Update query

Try using different quotes for "y" as the identifier quote character is the backtick (`). Otherwise MySQL "thinks" that you point to a column named "y".

See also MySQL 8 Documentation

Please use double-/single quotes for values, strings, etc.
Use backticks for column-names only.

New column - multiple conditions from multiple rows and columns

df |>
group_by(id) |>
mutate(train_avail = {
car <- min(duration[main_mode == "car"])
if_else(main_mode == "train",
if_else(duration > 2* car, 0, 1),
NA_real_)
})

##> + # A tibble: 8 × 4
##> # Groups: id [3]
##> main_mode duration id train_avail
##> <chr> <int> <int> <dbl>
##> 1 train 1250 1 0
##> 2 train 900 1 1
##> 3 car 540 1 NA
##> 4 train 650 2 1
##> 5 car 450 2 NA
##> 6 plane 350 2 NA
##> 7 train 350 3 1
##> 8 car 890 3 NA

Understand the warning message in across in R

There is not much difference between using where and not using it. It just shows a warning to suggest a better syntax. Basically where takes a predicate function and apply it on every variable (column) of your data set. It then returns every variable for which the function returns TRUE. The following examples are taken from the documentations of where:

iris %>% select(where(is.numeric))
# or an anonymous function
iris %>% select(where(function(x) is.numeric(x)))
# or a purrr style formula as a shortcut for creating a function on the spot
iris %>% select(where(~ is.numeric(.x)))

Or you can also have two conditions using shorthand &&:

# The following code selects are numeric variables whose means are greater thatn 3.5
iris %>% select(where(~ is.numeric(.x) && mean(.x) > 3.5))

You can use select(where(is.character)) for .cols argument of the across function and then apply a function in .fns argument on the selected columns.
For more information you can always refer to documentations which are the best source to learn more about these materials.



Related Topics



Leave a reply



Submit