mutate

Change Date Format from %y-%m-%d %h:%m:%s to %Y%M%D with lubridate and mutate

拥有回忆 提交于 2021-01-03 04:00:42
问题 I've got a tbl_df with two columns StartTime and StopTime . Both are dttm . I want to change its format from "%y-%m-%d %h:%m:%s" to "%y%m%d" . I've tried data <- mutate(data, StartTime = ymd(StartTime), StopTime = ymd(StopTime)) But it returns Warning messages: 1: All formats failed to parse. No formats found. 2: All formats failed to parse. No formats found. How can I do it? Please, don't send other questions that don't use lubridate package. Thanks 回答1: I think this should work library

Change Date Format from %y-%m-%d %h:%m:%s to %Y%M%D with lubridate and mutate

我怕爱的太早我们不能终老 提交于 2021-01-03 03:56:12
问题 I've got a tbl_df with two columns StartTime and StopTime . Both are dttm . I want to change its format from "%y-%m-%d %h:%m:%s" to "%y%m%d" . I've tried data <- mutate(data, StartTime = ymd(StartTime), StopTime = ymd(StopTime)) But it returns Warning messages: 1: All formats failed to parse. No formats found. 2: All formats failed to parse. No formats found. How can I do it? Please, don't send other questions that don't use lubridate package. Thanks 回答1: I think this should work library

Divide all columns by a chosen column using mutate_all

好久不见. 提交于 2020-12-23 09:46:13
问题 I have a sample data frame that looks like this (my full dataframe has "d" plus 57 elements): d <- seq(0, 100, 0.5) Fe <- runif(201, min = 0, max = 1000) Ca <- runif(201, min = 0, max = 1000) Zr <- runif(201, min = 0, max = 1000) Ti <- runif(201, min = 0, max = 1000) Al <- runif(201, min = 0, max = 1000) example <- data.frame(d, Fe, Ca, Zr, Ti, Al) Ratio_Elements <- c("Fe", "Ti", "Zr", "d") #this subset of the dataframe is user defined Detrital_Divisor <- "Zr" The Detrital_Divisor can change

Divide all columns by a chosen column using mutate_all

人走茶凉 提交于 2020-12-23 09:45:34
问题 I have a sample data frame that looks like this (my full dataframe has "d" plus 57 elements): d <- seq(0, 100, 0.5) Fe <- runif(201, min = 0, max = 1000) Ca <- runif(201, min = 0, max = 1000) Zr <- runif(201, min = 0, max = 1000) Ti <- runif(201, min = 0, max = 1000) Al <- runif(201, min = 0, max = 1000) example <- data.frame(d, Fe, Ca, Zr, Ti, Al) Ratio_Elements <- c("Fe", "Ti", "Zr", "d") #this subset of the dataframe is user defined Detrital_Divisor <- "Zr" The Detrital_Divisor can change

Why does dplyr recode generate error when recoding to NA but not NaN

风格不统一 提交于 2020-12-12 14:37:51
问题 I'm recoding with dplyr. I'm getting an error when I recode a value to NA, but not NaN. Here's an example: df <- df %>% mutate(var=recode(var,`2`=0,`3`=NaN)) Works fine, whereas df <- df %>% mutate(var=recode(var,`2`=0,`3`=NA)) gives me the following error: Error: Vector 2 must be a double vector, not a logical vector 回答1: When running the code you get this error tibble(var = rep(2:3, 4)) %>% mutate(var=recode(var,`2`=0,`3`=NA)) # Error: Vector 2 must be a double vector, not a logical vector