[Solved] How to calculate the mean of a group in R [closed]

Here you go. library(dplyr) Mean_of_a_group <- dataset %>% group_by(age_group) %>% summarize(happy = mean(happy)) I suggest using ggplot2 to do what you want here. ggplot(data = Mean_of_a_group, aes(age_group, happy))+ geom_point Dummy example library(ggplot2) ggplot(aes(x = disp, y= mpg), data = mtcars)+ geom_smooth(aes(colour = “red”), data = mtcars, stat = “smooth”, formula = y ~ x , … Read more

[Solved] Finding proportion by Id and by loan purpose in R

Make use of the standard old table and prop.table functions: tmp <- table(dat) data.frame(prop.table(tmp ,1))[tmp != 0,] # Id Loan Freq #1 94 Expansion 0.6666667 #5 95 Inventory 0.3333333 #7 94 Working Capital 0.3333333 #8 95 Working Capital 0.6666667 #9 99 Working Capital 1.0000000 solved Finding proportion by Id and by loan purpose in R

[Solved] Linear Regression in R – coef Function

Please read the help page before you post a question. ?coef says that: coef is a generic function which extracts model coefficients from objects returned by modeling functions Therefore, you need to run a linear model using lm() on your data-set, then extract the coefficients from the model: coef(lm(…)) solved Linear Regression in R – … Read more

[Solved] Stacked bar chart in R [closed]

Please have a look at how to ask questions on SO and how to provide data/examples. It makes it a lot easier for people to help you if we have all the information ready to go. The data I’ve produced a table using some of your data: library(tidyverse) df <- tribble(~absent, ~present, ~total, ~session, 15,8,3,’s1′, … Read more

[Solved] Creating multiple files in R with a content inside [closed]

Use a for loop and write_lines for example: for(i in 1:100) { write_lines(“Hello World”, path = sprintf(“file%s.txt”, i))# } or use mapply mapply(write_lines, path = sprintf(“file%s.txt”, 1:100), x = “Hello World”) 1 solved Creating multiple files in R with a content inside [closed]

[Solved] Match a character in string and add characters before and after matched string using R [closed]

I modified the code to include the strings in single quotes. (R requires single or double quotes for strings. I used single quotes so as not to have to escape the double quotes.) Before <- ‘kzyFw4hw8EOC/655’ After <- ‘kzyFw4hw8EOC”https://stackoverflow.com/”655’ Using base R: gsub.method <- gsub(“https://stackoverflow.com/”, ‘”https://stackoverflow.com/”‘, Before) gsub.method == After # [1] TRUE or using … Read more

[Solved] How can I remove some elements from a list?

As simple test<-list(list(17413624, “item”, 4167836), list(17413611, “item”, 15284), list(17413151, “item”, 11266439), list(17413068, “item”, 4663903), list(17413056, “item”, 694589), list(17413006, “item”, 4167836), list(17412951, “item”, 4167836), list(17412582, “item”, 1972868), list(17412061, “item”, 4167836), list(17411835, “item”, 4167836)) removed <- lapply(test, `[`, -2) would work just fine. solved How can I remove some elements from a list?

[Solved] Conditional summation in r

df <- data.frame(rep=c(0.2,0.3,0.2), lon=c(35,36,37), lat=c(-90,-91,-92), v1=c(10,0,8), v2=c(3,4,5), v3=c(9,20,4)) v <- as.vector(“numeric”) for(i in 1:3) v[i] <- sum(df$rep[df[,i+3]!=0]) solved Conditional summation in r