Category "r"

Read .csv file in R

I am a beginner to R, I have a file like below. state population Alabama 4779736 Alaska 710231 Arizona 6392017

What does the specified number 1 in this code mean?

for (i in 1:25) { pid.means[,i] = apply(get(paste("pid.tf",i,sep="")), 1, mean, na.rm = TRUE) } I understand the function of this for loop, but i can't fin

How to split legend of a plotly chart when using to two y axes

I am creating a grouped bar plot using plotly. As level of my values differ I am using two y axes. I would like to split a legend (idea presented on a picture

R replace string in df with partial match in a list

I have a dataframe (df) in R and I want to create a new column (city1_n) that contains a line stored in the list key whenever there is a partial match between c

Shell using path pulled from cell in workbook using VBA

My code runs a model in R directly from Excel. I want to simplify installation so instead of: path = """C:\Program Files\R\R-4.1.1\bin\Rscript.exe"" C:\Users\di

R Studio Fatal error: 'R_TempDir'contains space

I tried to download the latest version (4.2.0) of R on my windows computer and received this error message upon trying to open the program. "Fatal error: 'R_Te

How can I make one plot from multiple variables in ggplot?

I'm trying to make a pre-post change plot for three groups. In my data frame, pre data and post data are stored as two different variables like this. pre_treat

Tried scale_linetype_manual to add legend but not successful

Following the thread from Tried p + scale_fill_discrete(name = "New Legend Title") but legend title still not changing, I now only want to generate line plot wi

How to create a dummy variable corresponding to a change in a value in R

I have the following data: week <- c(1,2,3,4,1,2,3,4,1,2,3,4) product <- c("A", "A", "A", "A", "B", "B", "B", "B", "C", "C", "C", "C") price <- c(5,5,6

gridtext::element_markdown doesn't apply margin with css selector

I'm trying to define different margins for x-axis labels in ggplot2 using css syntax, as allowed by ggtext package. I created an object with the CSS selector an

Multiples rows to one row in R [closed]

In R, I have a data frame with several values. I would like to have a data frame that transforms the data frame into a data frame with just on

Error in deployment of shinyapps Error accessing GitHub repository nstrayer/shinysense. HTTP 401: Unauthorized

I am trying to publish a shiny app, you can see the source code here, it was being deployed correctly until I tried using the shinysense package This is the err

How to extract the coefficients of a linear model and store in a variable in R?

I have a data frame and I did a linear model. I want to extract the coefficients and store each coefficient into a variable using R. This is my data frame df &l

Split comma-separated strings in a column into separate rows

I have a data frame, like so: data.frame(director = c("Aaron Blaise,Bob Walker", "Akira Kurosawa", "Alan J. Pakula", "Alan Parker", "A

Summarize two dataframes in r

I have two dataframes df1 # var1 var2 # 1 X01 Red # 2 X02 Green # 3 X03 Red # 4 X04 Yellow # 5 X05 Red # 6 X06 Green df2 # X01 X02

Rmarkdown: include plot height in resulting html <img> tag

I am working on a larger RMarkdown-site. Due to the size of images on the pages I implemented lazy loading for images using the loading="lazy"attribute of the &

Assigning different types of tasks to the same `foreach` loop

Many are familiar with foreach() to assign a loop across many cores in parallel using %dopar%. However, in R how do you send a single job request for a variety

mixed effect model with more than two uncorrelated random effect slopes in python

I have multi-level data and want to fit a mixed-effect model in python due to parallelization potential. But I am not able to compile the formula in 'statsmodel

Configuring compilers on Mac M1 (Big Sur, Monterey) for Rcpp and other tools

I'm trying to use packages that require Rcpp in R on my M1 Mac, which I was never able to get up and running after purchasing this computer. I updated it to Mon

R - subscript out of bounds with stringer and grep in lapply function

My goal is to extract strings of digits with fixed length (8 digits) from multiple text files in several folders after matching a certain pattern. I have spent