/r/RStudio
A place for users of R and RStudio to exchange tips and knowledge about the various applications of R and RStudio in any discipline.
Please use this as a forum to discuss R, and learn more about it. If you have any questions about how to do specific things in R, this is the place to ask. If you are looking for more advanced help using R, please visit /r/Rstats.
You can download R itself here.
You can download RStudio here. It is an incredibly powerful IDE for R, and what the mods recommend you use.
NOTE: Due to a couple of recent posts offering "compensation" for help with an assignment let's make this official: You are not allowed to offer payment for help with an assignment. If you want help with an assignment please post the work you've done/completed so far and highlight the issue you are having. Members will then help where they can. If you desire to pay someone for tutoring in R this is not the place to look for it.
/r/RStudio
I'm trying to create a plot using R in Power BI. I've loaded the dataset, installed the necessary libraries, and tested the plot in RStudio, where it works perfectly. However, when I try to run it in Power BI, nothing shows up. Any ideas on what might be causing this?
I installed rstudio-desktop-bin
using paru. Can't launch it though.
>> rstudio
zsh: command not found: rstudio
Any idea what's wrong? How to launch it?
I found an API for python and nodejs on Deepseek, but haven’t come across anything for R yet. Anyone know if they’ve released one or if there’s a workaround?
Hello, I have a doubt, can you actually make a DAG model for a Structural Regression Model? I have been trying to do the next model for my homework.
modelo_dag <- ggm::DAG(CMcg~Mcg, EsMcg~Mcg, ExMcg~Mcg, MT~FE, Inhb~FE, Flex~FE, HP1~HP, HP2~HP, HP3~HP, HP~FE, HP~Mcg, Tarea~FE, Tarea~Mcg, Tarea~HP, FE~Mcg, Puntos~Tarea)
And I do not know how to make it clear that "Mcg", "FE", "HP", and "Tarea" are latent variables (here factors) in the model. In fact, the graphical model is correct (with what I have in mind), but it is not represented in a squared form for latent variables indicators as I was able to generate in the online dagitty web page.
ggm::drawGraph(modelo_dag) #the R version
Does someone know how to do that? Or is it even possible?
Hello Everyone!
So I am in need of support with the installation of Data explorer.
I need it for a class, and I tried to download it as usual from the packages page, however I am getting errors:
> install.packages("DataExplorer")
Warning in install.packages :
dependencies ‘gtable’, ‘MASS’, ‘Matrix’, ‘cpp11’, ‘lattice’ are not available
also installing the dependencies ‘fs’, ‘cli’, ‘colorspace’, ‘nlme’, ‘cachem’, ‘fastmap’, ‘memoise’, ‘sass’, ‘plyr’, ‘farver’, ‘lifecycle’, ‘munsell’, ‘rlang’, ‘isoband’, ‘mgcv’, ‘vctrs’, ‘bslib’, ‘fontawesome’, ‘htmltools’, ‘knitr’, ‘tinytex’, ‘xfun’, ‘igraph’, ‘data.table’, ‘reshape2’, ‘scales’, ‘ggplot2’, ‘gridExtra’, ‘rmarkdown’, ‘networkD3’
Warning in install.packages :
unable to access index for repository https://cran.rstudio.com/bin/windows/contrib/3.6:
cannot open URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/PACKAGES'
Packages which are only available in source form, and may need compilation of C/C++/Fortran: ‘fs’ ‘cli’ ‘colorspace’ ‘nlme’ ‘cachem’ ‘fastmap’
‘sass’ ‘plyr’ ‘farver’ ‘rlang’ ‘isoband’ ‘mgcv’ ‘vctrs’ ‘htmltools’ ‘xfun’ ‘igraph’ ‘data.table’ ‘reshape2’ ‘scales’
These will not be installed
installing the source packages ‘memoise’, ‘lifecycle’, ‘munsell’, ‘bslib’, ‘fontawesome’, ‘knitr’, ‘tinytex’, ‘ggplot2’, ‘gridExtra’, ‘rmarkdown’, ‘networkD3’, ‘DataExplorer’
trying URL 'https://cran.rstudio.com/src/contrib/memoise\_2.0.1.tar.gz'
Content type 'application/x-gzip' length 17852 bytes (17 KB)
downloaded 17 KB
trying URL 'https://cran.rstudio.com/src/contrib/lifecycle\_1.0.4.tar.gz'
Content type 'application/x-gzip' length 107656 bytes (105 KB)
downloaded 105 KB
trying URL 'https://cran.rstudio.com/src/contrib/munsell\_0.5.1.tar.gz'
Content type 'application/x-gzip' length 182310 bytes (178 KB)
downloaded 178 KB
trying URL 'https://cran.rstudio.com/src/contrib/bslib\_0.9.0.tar.gz'
Content type 'application/x-gzip' length 5428353 bytes (5.2 MB)
downloaded 5.2 MB
trying URL 'https://cran.rstudio.com/src/contrib/fontawesome\_0.5.3.tar.gz'
Content type 'application/x-gzip' length 1320479 bytes (1.3 MB)
downloaded 1.3 MB
trying URL 'https://cran.rstudio.com/src/contrib/knitr\_1.49.tar.gz'
Content type 'application/x-gzip' length 545754 bytes (532 KB)
downloaded 532 KB
trying URL 'https://cran.rstudio.com/src/contrib/tinytex\_0.54.tar.gz'
Content type 'application/x-gzip' length 35584 bytes (34 KB)
downloaded 34 KB
trying URL 'https://cran.rstudio.com/src/contrib/ggplot2\_3.5.1.tar.gz'
Content type 'application/x-gzip' length 3604371 bytes (3.4 MB)
downloaded 3.4 MB
trying URL 'https://cran.rstudio.com/src/contrib/gridExtra\_2.3.tar.gz'
Content type 'application/x-gzip' length 1062844 bytes (1.0 MB)
downloaded 1.0 MB
trying URL 'https://cran.rstudio.com/src/contrib/rmarkdown\_2.29.tar.gz'
Content type 'application/x-gzip' length 2194660 bytes (2.1 MB)
downloaded 2.1 MB
trying URL 'https://cran.rstudio.com/src/contrib/networkD3\_0.4.tar.gz'
Content type 'application/x-gzip' length 128302 bytes (125 KB)
downloaded 125 KB
trying URL 'https://cran.rstudio.com/src/contrib/DataExplorer\_0.8.3.tar.gz'
Content type 'application/x-gzip' length 2426666 bytes (2.3 MB)
downloaded 2.3 MB
ERROR: dependency 'cachem' is not available for package 'memoise'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/memoise'
Warning in install.packages :
installation of package ‘memoise’ had non-zero exit status
* installing *source* package 'lifecycle' ...
** package 'lifecycle' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace 'rlang' 0.3.4 is being loaded, but >= 1.1.0 is required
Calls: <Anonymous> ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
ERROR: lazy loading failed for package 'lifecycle'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/lifecycle'
Warning in install.packages :
installation of package ‘lifecycle’ had non-zero exit status
ERROR: dependency 'colorspace' is not available for package 'munsell'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/munsell'
Warning in install.packages :
installation of package ‘munsell’ had non-zero exit status
* installing *source* package 'fontawesome' ...
** package 'fontawesome' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace 'htmltools' 0.3.6 is being loaded, but >= 0.5.1.1 is required
Calls: <Anonymous> ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
ERROR: lazy loading failed for package 'fontawesome'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/fontawesome'
Warning in install.packages :
installation of package ‘fontawesome’ had non-zero exit status
* installing *source* package 'knitr' ...
** package 'knitr' successfully unpacked and MD5 sums checked
** using staged installation
** R
** demo
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
namespace 'xfun' 0.6 is being loaded, but >= 0.48 is required
Calls: <Anonymous> ... namespaceImportFrom -> asNamespace -> loadNamespace
Execution halted
ERROR: lazy loading failed for package 'knitr'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/knitr'
* restoring previous 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/knitr'
Warning in install.packages :
installation of package ‘knitr’ had non-zero exit status
* installing *source* package 'tinytex' ...
** package 'tinytex' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
namespace 'xfun' 0.6 is being loaded, but >= 0.48 is required
Calls: <Anonymous> ... namespaceImportFrom -> asNamespace -> loadNamespace
Execution halted
ERROR: lazy loading failed for package 'tinytex'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/tinytex'
* restoring previous 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/tinytex'
Warning in install.packages :
installation of package ‘tinytex’ had non-zero exit status
ERROR: dependency 'gtable' is not available for package 'gridExtra'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/gridExtra'
Warning in install.packages :
installation of package ‘gridExtra’ had non-zero exit status
ERROR: dependency 'igraph' is not available for package 'networkD3'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/networkD3'
Warning in install.packages :
installation of package ‘networkD3’ had non-zero exit status
ERROR: dependencies 'cachem', 'fastmap', 'lifecycle', 'memoise', 'sass' are not available for package 'bslib'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/bslib'
Warning in install.packages :
installation of package ‘bslib’ had non-zero exit status
ERROR: dependencies 'gtable', 'isoband', 'lifecycle', 'MASS', 'mgcv', 'scales', 'vctrs' are not available for package 'ggplot2'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/ggplot2'
Warning in install.packages :
installation of package ‘ggplot2’ had non-zero exit status
ERROR: dependencies 'bslib', 'fontawesome' are not available for package 'rmarkdown'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/rmarkdown'
Warning in install.packages :
installation of package ‘rmarkdown’ had non-zero exit status
ERROR: dependencies 'data.table', 'reshape2', 'scales', 'ggplot2', 'gridExtra', 'rmarkdown', 'networkD3' are not available for package 'DataExplorer'
* removing 'C:/Users/tomas/anaconda3/envs/rstudio/lib/R/library/DataExplorer'
Warning in install.packages :
installation of package ‘DataExplorer’ had non-zero exit status
Does anyone know how to help me here?
I've had like 2 hours of R in class for now, so I am lost for now.
Thanks for the help!
So i made a header but when i knit it, it pops up underneath my plot and the codes. Anyone can help me on this
So my code goes like this:
summarytools::freq(cd$gender)
gender_rev <- recode(cd$gender, '1'= "Male", '2' = "Female" ,'3' = "Non-binary/third gender", '4' = "Prefer not to say", '5' = "Prefer to self-describe" ) %>%
as.factor()
cd <- cd %>%
mutate (gender_rev = as.numeric(gender_rev))
summarytools::freq(cd$gender_rev)
But in the output of "gender_rev" I am not getting the labels like Male, Female er=tc. What exactly am I doing wrong?
Wondering if anyone here might know how to do this - I've been using tinygeocoder to process address data (I have around 400) to pull relevant geo data, but realized that the tracts are from 2020. Is there a way to easily process address data (or even lat/long coordinates) into 2010 census tracts in R?
I ran a two-way ANOVA with nominal independent variables "NRGEOGP" and "PARGP" and ratio dependent variable "TMCHG." The ANOVA resulted in a statistically significant p-value, but a Tukey post-hoc did not result in any significance amongst the unique variable combinations. I am attempting to run a Fisher's LSD test to see what those results may be, but am not able to get it to work in RStudio. Test Data Set is attached as screenshot
I have installed and added the "agricolae" package to my library.
I have attempted code:
'''aov1 <- testdata %>%
aov(TMCHG ~ PARGRP * NRGEOGRP, data = .)
lsd1 <- LSD.test(aov1, trt = "PARGRP * NRGEOGRP")
summary(lsd1)'''
Results posted as image screen shot "lsd1 Results"
I've watched some videos about the data set needing to be a factor maybe? I've played with that but don't really understand enough to know what is going on. Thoughts?
Hi everyone,
I am trying to generate KDE home ranges for rhinos using the adehabitatHR package. Each rhino has a different total GPS location points (ranging from 20-150). I tried using "href" but it overestimated the ranges. While using "LSCV" produced home ranges fragmented to a point where most GPS location dots were visible. I have been playing around using a manually chosen smoothing factor (h).
Has anyone worked with KDE home ranges in R before and did you use the same "h" value for all individuals (e.g. h= 500) or use a different h value for each individual based on their corresponding data set? If using different h values for each individual, how did you choose which h value to use?
Thanks so so much in advance!
Hey everyone!
I’m working on regression predictions using Random Forest in R. I chose Random Forest because I’m particularly interested in variable importance and the decision trees that will help me later define a sampling protocol.
However, I’m confused by the model’s performance metrics:
rf_model$rsq
) is around 20%.I can’t understand how this discrepancy is possible.
To investigate further, I tested the same approach on the iris dataset and found a similar pattern:
Here’s the code I used:
library(randomForest)
library(dplyr)
set.seed(123) # For reproducibility
# Select only numeric columns from iris dataset
iris2 <- iris %>%
select(Sepal.Length, Sepal.Width, Petal.Length, Petal.Width)
# Train a Random Forest model
rf_model <- randomForest(
Sepal.Length ~ .,
data = iris2,
ntree = 100,
mtry = sqrt(ncol(iris2) - 1), # Use sqrt of the number of predictors
importance = TRUE
)
# Make predictions
predicted_values <- predict(rf_model, iris2)
# Add predictions to the dataset
iris2 <- iris2 %>%
mutate(Sepal.Length_pred = predicted_values)
# Compute R² using a simple linear regression
lm_model <- lm(Sepal.Length ~ Sepal.Length_pred, data = iris2)
mean(rf_model$rsq) # % Variance Explained
summary(lm_model)$r.squared # R² of predictions
Does anyone know why the % Variance Explained is low while the R² from the regression is so high? Is there something I’m missing in how these metrics are calculated? I tested different data, and i always got similar results.
Thanks in advance for any insights!
Thinking about attending this year's conference (https://posit.co/conference/), but they are quite expensive. Other than trying to convince my boss to expense it (might be hard due to all the cost cutting measures), wondering if there are discount code that can help lessen the price tag burden?
Hi everyone. I am a 3rd year political science major and my Uni has a mandatory RStudio class for all polisci majors. I am applying to Pew Research for a summer internship around survey methods and journal publishing. I’d imagine that I would have to be proficient in it for working there. Just wondering if anyone is a polisci grad and can explain what kind of work you do that involves R. I have been enjoying the class and it’s completely new to me. Thanks!
Hello everyone!
I have recently been using the dygraphs package for building dashboards, with flexdashboards.
I have two minor questions in that regard:
-first, would you know if I can, once the chart appears on the dashboard, activate and deactivate certain curves? Say my initial data shows 3 series: inflation rate, interest rate and real rate. Can I toggle off the real rate at will?
-second, is there any way to, from the dashboard, export the chart as an image to be used for a powerpoint? For example, using a range selector, I want to show only the data from 1970 to 1985. Would I be able to export the chart modified this way?
-finally, how do I plot the dates as quarters instead of the dates I labelled in my ts object? (e.g. 2025Q2 instead of april 2025)
Thanks in advance.
Hi, I am new to R. I have a multivariate analysis where my dependent variable, y =1 (event) and y=2 (non-event). I was wondering how I should interpret my estimates. Lets say my independent variables are X1=-1, X2=5, X3=-2. Does this mean that X1 reduces the risk of event or increase it when X2 and X3 is constant? And what about X2?
I hope you can help. I am so confused.
Hello all, I am struggling after watching videos on youtube and in my course. I have a dataset and understand how to load it but that is pretty much the extent of how far I have been able to get. I need to create a data quality report for a dataset I have, a boxplot for a specific value on a single visualization, and a histogram. Just looking for help!
can someone please help me i'm using the R package AeRobiology to make a violin plot but the package just wont let me change the colour scheme im so confused, its just always yellow.
pollen_calendar(data, method = "violinplot", n.types = 15,
start.month = 1, y.start = NULL, y.end = NULL, perc1 = 80,
perc2 = 99, th.pollen = 1, average.method = "avg_before",
period = "daily", method.classes = "exponential", n.classes = 5,
classes = c(25, 50, 100, 300), color = "green",
interpolation = TRUE, int.method = "lineal", na.remove = TRUE,
result = "plot", export.plot = FALSE, export.format = "pdf",
legendname = "Pollen grains / m3")
Have you used the new Positron IDE from posti?
I really liked the premise but didnt install it yet.
We cant fully replace Rstudio by Positron yet because it doesn’t have all RStudio’s features; some notable absences are inline output for Quarto and R Markdown, profiling, Sweave, RStudio Add-In support, etc.. But I would love a better integration from R and Python.
IT has moved to only allowing interactive logon to a computer using accounts with user level (non administrative) rights and this seems to cause RStudio to drastically slow down. This slow down appears to impact everything from loading packages to running code.
Customers are still allowed administrative accounts to be used sparingly but one customer has used this admin account to right click run RStudio and when doing this has restored software performance to acceptable levels.
I was hoping the community could confirm this behavior.
capwire shows in .packages(all.available = TRUE) but install.packages("capwire") fails: package ‘capwire’ is not available for this version of R What does that mean?
I open a shiny app from cmd file, when I close the cmd ( the black window) I want the browser shiny window to close also. if it is not possible I want the waiter to stop and not give people the illusion that the code is still running on the shiny browser.
Posting this again but with a computer screenshot (I didn't know phone pictures weren't allowed). I'm new to RStudio since I need it for a class I'm taking. I'm just getting used to the basics but I'm having trouble understanding what's wrong with the code I'm typing. Can I not make collections with characters? Do they have to be numbers? It just keeps telling me an object isn't being found. Any help is appreciated!
Last semester, I had to learn the basis for R and, surprisingly, I really liked it. But now I feel that my knowledge is pretty vague and, honestly, don't really know what can I do to apply what I learned and at the same time learn more. FYI: What I did before was looking through governmental surveys and make graphics with the data (with the previous debugging of the database). I used the next set of libraries: haven, tidyverse, sjPlot, boxplot, ggplot
So my questions would be: What projects can I do now? What skills do you find useful? What do you use R for? (as in just work/education related or can it be used for personal purposes) Should I try learning Python?
Any answer is welcomed! I consider myself as really patient when is about coding and I like to look for errors so I'm open to more challenging stuff than what I have mentioned! :-)
I have a dataset with several categorical variables. I need to convert them to numeric to use them with the classification models I'm doing in class. I'm hoping someone can help me determine the best approach.
Some of the variables I have are country, currency, and payment type. Right now I'm trying to use the nearest neighbor algorithm but I'll be doing others throughout the course. What's the best way for me to manipulate these variables into meaningful numeric data?
Are slicers/filters available in q dashboards? I am looking to build a report but need slicers.
Hi guys, I have a task for stochastic system class and I struggled for one week.
Consider the following scenario. You know from your running apps that you can run 1 mile pretty reliably, meaning 99 percent of the time, you can run a mile between 9 and 10 minutes. A 𝑀(5)/𝑀(5.1)/1 queue is 1 mile away–here it is a rate of 5 customers per minutes. Estimate the probability that that you will make to through the queue within 20 minutes. Make clear any assumptions you are using for your calculations/simulations. Part of this exericse is to come up with reasonable modelling assumptions. Give one answer than you can do without any complicated calculations–like one that you can perform while you are running and deciding if you will make it or now, and give another answer that you think is more accurate and makes better use of the available information. Discuss the differences in your numerical answers.
I did the simple one just by calculating but not coding. For 𝜆=5 and 𝜇=5.1: 𝑊=1/0.1=10 minutes. Total Time: Running + Queue Time = 9.5+10=19.5 minutes. This assumes nobody is in the queue. For the accurate one, I think simulation should be used but have no idea of how to code it. I appreciate a lot if anyone could help!
Hey everyone. I have a Research Report/Project that I need to submit by 2 February in a "Data Analysis in R" university course. It can be up to 8 pages. I don't even know where to start as this is not my strongest suit :(. I would really appreciate it if someone here in this subreddit had maybe a small leftover project that wouldn't be too much trouble sharing with me. I will of course make adjustments to it and not submit the exact same thing. I have uploaded some pics of the requirement.