Here is my code:
library(tidyr)
messy <- data.frame(
name = c("Wilbur", "Petunia", "Gregory"),
a = c(67, 80, 64),
b = c(56, 90, 50)
)
And I would like to use gather
function with variable/function result. Borrowing from I tried:
not_messy <-messy %>%
gather_('drug', 'heartrate', paste0('a',''):paste0('b',''))
But it generated error:
Error in paste0("a", ""):paste0("b", "") : NA/NaN argument
In addition: Warning messages:
1: In lapply(.x, .f, ...) : NAs introduced by coercion
2: In lapply(.x, .f, ...) : NAs introduced by coercion
What am I missing?
With the latest version of the tidyverse functions, you are discouraged from using the underscore versions of the function for standard evaluation and instead use the rlang function syntax. In this case you can use
gather(messy, "drug", "heartrate", (!!as.name("a")):(!!as.name("b")))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.