r

Error using 'segmented' with lm extracted from output of tidyverse 'map' in R

跟風遠走 提交于 2021-02-17 02:50:17
问题 I am using the 'segmented' package to find break points in linear regressions in R library(tidyverse) library(segmented) df <- data.frame(x = c(1:10), y = c(1,1,1,1,1,6:10)) lm_model <- lm(y ~ x, data = df) seg_model <- segmented(obj = lm_model, seg.Z = ~ x) But if I run the same model within a purrr:map, segmented fails. map_test <- df %>% nest() %>% mutate(map_lm = map(data, ~lm(y ~ x, data = .)), param_map_lm = map(map_lm, tidy)) map_lm_model <- map_test[[2]][[1]] map_seg_model <-

Combine Rarely Used Factor Levels Across all Factors in Data Frame

筅森魡賤 提交于 2021-02-17 02:37:31
问题 I would like to combine factor levels that are used fewer than 5 times for each factor in a dataset containing many different factors. While I understand that the fct_lump() function in the forcats package can help me achieve this for a single factor, is there a function where I can apply the fct_lump() function over all the factors in my dataset? 回答1: We can check whether the column is factor with mutate_if and apply fct_lump library(dplyr) library(forcats) df1 %>% mutate_if(is.factor, fct

How to detect more than one regex in a case_when statement

﹥>﹥吖頭↗ 提交于 2021-02-17 02:28:06
问题 I have recently converted from ifelse to case_when from dplyr . Aim I would like to be able to detect more than one regex from a statement in a dataframe using case_when as follows: Input statement<-data.frame(statement = c("I have performed APC and RFA", "An EMR was done","I didn't do anything"),stringsAsFactors=FALSE) Desired output statement out I have performed APC and RFA APC,RFA An EMR was done EMR I didn't do anything No Event Attempt library(dplyr) library(stringr) dataframe <-

ERROR:`data` must be a data frame, or other object coercible by `fortify()`, not an S3 object with class reactiveExpr/reactive

大城市里の小女人 提交于 2021-02-17 02:01:06
问题 I am trying to build a Corona Dashboard. Where If someone selects State from the dropdown, District wise cases to be displayed in the graph. E.g. If someone selects Gujarat, it shows district wise cases in Bar chart. Someone change it to Maharashtra, It should update with the district of Maharashtra. But I am getting "ERROR: data must be a data frame, or other object coercible by fortify() , not an S3 object with class reactiveExpr/reactive " error. library(shiny) library(readxl) library

Name of a custom fuction in Keras model R

自作多情 提交于 2021-02-17 01:51:40
问题 I have created a custom loss function: RMSE= function(y_true,y_pred){ k_sqrt(k_mean(k_square(y_pred-y_true))) } And it works fine but when I run: model$loss Get: <function make_python_function.<locals>.python_function at 0x0000026A51F5c80> Instead of the name of the loss function, like when I used for example 'mse' model$loss "mse" What should I add to my custom function to be able to get the name? 来源: https://stackoverflow.com/questions/60599127/name-of-a-custom-fuction-in-keras-model-r

converting multiple date formats into one in r

笑着哭i 提交于 2021-02-16 23:39:09
问题 I am working with messy excel file with multiple date formats 2016-10-17T12:38:41Z Mon Oct 17 08:03:08 GMT 2016 10-Sep-15 13-Oct-09 18-Oct-2016 05:42:26 UTC I want to convert all of the above in yyyy-mm-dd format. I am using following code for the conversion but lot of values are coming NA. as.Date(parse_date_time(df$date,c('mdy', 'ymd_hms','a b d HMS y','d b y HMS'))) How can I do it all of them together. I have read other threads on similar case,but nothing seems to work for my case. Please

converting multiple date formats into one in r

痴心易碎 提交于 2021-02-16 23:36:45
问题 I am working with messy excel file with multiple date formats 2016-10-17T12:38:41Z Mon Oct 17 08:03:08 GMT 2016 10-Sep-15 13-Oct-09 18-Oct-2016 05:42:26 UTC I want to convert all of the above in yyyy-mm-dd format. I am using following code for the conversion but lot of values are coming NA. as.Date(parse_date_time(df$date,c('mdy', 'ymd_hms','a b d HMS y','d b y HMS'))) How can I do it all of them together. I have read other threads on similar case,but nothing seems to work for my case. Please

converting multiple date formats into one in r

ⅰ亾dé卋堺 提交于 2021-02-16 23:36:40
问题 I am working with messy excel file with multiple date formats 2016-10-17T12:38:41Z Mon Oct 17 08:03:08 GMT 2016 10-Sep-15 13-Oct-09 18-Oct-2016 05:42:26 UTC I want to convert all of the above in yyyy-mm-dd format. I am using following code for the conversion but lot of values are coming NA. as.Date(parse_date_time(df$date,c('mdy', 'ymd_hms','a b d HMS y','d b y HMS'))) How can I do it all of them together. I have read other threads on similar case,but nothing seems to work for my case. Please

converting multiple date formats into one in r

十年热恋 提交于 2021-02-16 23:36:12
问题 I am working with messy excel file with multiple date formats 2016-10-17T12:38:41Z Mon Oct 17 08:03:08 GMT 2016 10-Sep-15 13-Oct-09 18-Oct-2016 05:42:26 UTC I want to convert all of the above in yyyy-mm-dd format. I am using following code for the conversion but lot of values are coming NA. as.Date(parse_date_time(df$date,c('mdy', 'ymd_hms','a b d HMS y','d b y HMS'))) How can I do it all of them together. I have read other threads on similar case,but nothing seems to work for my case. Please

Generating strings combining letter and number sequences in R

点点圈 提交于 2021-02-16 21:39:47
问题 How can i generate this vector in R: x <- c("R11", "R12", "R13", "R21", "R22", "R23", "R31",....) until R7xx for a set of six letters (R, S, D, A, B, X) ? and so on? Without actually typing it. 回答1: Try something like this: m <- expand.grid(c('A','B','D','R','X'),1:7,1:3) apply(m,1,paste0,collapse = "") One way to force a specific, non-alphabetic ordering would be to explicitly indicate it using a factor and then order the results from expand.grid : m <- expand.grid(factor(c('R','A','B','D',