Categories
Mastering Development

Imputation based on predefined values

In this df, only apple has NAs and I’d like them to take only the values 21, 31 or 32. > head(df) # A tibble: 6 x 5 apple apricot avocado banana `bell pepper` <fct> <fct> <fct> <fct> <fct> 1 31 68 66 31 4 2 22 22 75 48 1 3 NA 34 75 […]

Categories
Mastering Development

Model failed to converge with max|grad|

When I ran a mixed model with lme4 I got this error message, but I still get some results from the summary: model2<-lmer(rating.Hz.dif ~ is.congruent + is.positive + (1 |num)+ (1|Hz.Hz.dif) + (1+is.congruent|dot.Hz.dif), data=data_pilot) ## Warning in checkConv(attr(opt, "derivs"), opt$par, ctrl = control$checkConv, : ## Model failed to converge with max|grad| = 0.00432249 (tol = […]

Categories
Mastering Development

R conditional loop to replace vallues

I am looking to conditionally replace values in a column and I think a loop is what I need. Though I know on a basic level how loops work, I have little experience using them so I struggle with wrapping my head around the order of operations. Using the dataframe df <- structure(list(player = c(“p1”, […]

Categories
Mastering Development

data.table equivalent for: case_when – Invalid regex when using emails on it?

I’ve a list of emails, I want to compare against a DB column, named correo (spanish for email). So, let’s say this is the list of emails to use: users_emails <-“18maryalma@gmail.com|2013311097@edu.pe|40491118@cotal.edu.pe|956145120jh@gmail.com|975625735o@gmail.com” When using case_when and grepl to match them to the data base, I get: Error in grepl(users_emails, correo, ignore.case = TRUE) : invalid regular […]

Categories
Mastering Development

how to drop multiple column which has categorical values in R?

I know how to drop columns by name, but I am not quite sure how I am going to drop the columns which has categorical values. It can be done manually looking at which columns has categorical values, but not intuitive for me using R code. How to detect columns which has categorical values? any […]

Categories
Mastering Development

Why do I get differing legends in ggplot while world mapping?

I am trying to plot the following DFs with ggplot2 and maps. I have no issue in the plot itself, yet the two legends look different. I tried different combinations, with breaks, setting limits, still the two differs. What I need is the legends for the two plots to be the same, with values having […]

Categories
Mastering Development

Why can´t I transform a tibble to data frame in R?

I have a tibble with information or 5 landcape metrics and 3 scales from 140 landscapes (from package landscapemetrics). Now I want to make models with it but I can´t because I can´t transform it to a data frame. [I have a tibble filtered][1], but then, when I use this function: MMB2 <- lapply(MMB.cls, function(x) […]

Categories
Mastering Development

How adjust a moderated moderated mediation model with processR package?

I want adjust a moderated moderated mediation model with lavaan and processR packages. The model is follow: I tried to create the following moderations: Innovativeness:Age and PBC:Innovativeness:Age My data (df): df <- structure(list(Attitude = structure(c(33, 30, 37, 29, 36, 42, 27, 35, 35, 27, 22, 25, 42, 25, 38, 35, 38, 36, 34, 40), label […]

Categories
Mastering Development

How can I manipulate my data to compute a mean in R with multiple NA instances?

I am using R studio and have an extremely large dataset which has 4 variables. I am trying to compute a mean for the hours between 06:30:00 and 19:00:00 of the O2 column for every day. A sample of the dataset looks like: RBWQ <- read.csv(“…/R/WY06 to WY19.csv”, skip = 2, header = TRUE, sep […]

Categories
Mastering Development

How to bring model predict line in front of geom_rect

I am investigating the effect of time since fire on species diversity. I am attempting to make a graph that has different colours at different time since fire ages. However, putting the colours onto the graph has made the model prediction line fade away. I am wondering if there is some way to bring the […]