Questions tagged [r]

R is a free, open-source programming language & software environment for statistical computing, bioinformatics, visualization & general computing. Please use minimal reproducible examples others can run using copy & paste. Show desired output entirely. Use dput() for data & specify all non-base packages with library(). Don't embed pictures for data or code, use indented code blocks instead. For statistics questions, use https://stats.stackexchange.com.

Filter by
Sorted by
Tagged with
0 votes
0 answers
16 views

How would I hypothetically display the number of iterations in this forloop?

In my hypothetical R code below, I am using two packages called "DBA" and "EBA" to generate data sets with missing data for the following sample sizes: 50, 150, 250, 350. This will ...
0 votes
0 answers
9 views

How to improve the efficiency of a function

I wrote this function to transform a dataset with categorical variables with only the observed combinations of categories into a dataset that contains all the possible combinations that can be found ...
  • 83
0 votes
0 answers
8 views

rstudio+github everyday problem with github token in RStudion (ubuntu)

I've made a public repo at GitHub connected with RStudio for perosnal R practices. Got a token, authorized, initiated the repo, commited, pushed, pulled... The very next day GitHub didn't see my token ...
1 vote
2 answers
18 views

Replacing commas and colon within ' '

I have a dataset with key-value pairs that I want to import into R. The keys and values are separated by colons, while the key-value pairs are separated by commas. However, some of the values contain ...
0 votes
0 answers
4 views

How to apply STL decomposition on a quarterly time series data using feasts package in R?

The time series data is a quarterly sales data, that is recored in Date Sales Q 2019Q1 2000 2019Q2 3000 2019Q3 2500 2019Q4 3200 I used the yq(date) function to convert Date in Character into ...
0 votes
0 answers
8 views

choropleth map using different polygons in the map for coloring

Trying to do a "simple" map display of a variable (Density) in several states in a shapefile from mexico. The addition of variables to the shapefile seems to be working fine, but when ...
0 votes
0 answers
11 views

RStudio View() a list of lists with repeated names gives different visual result from Environment

I recently spotted something weird with RStudio, see codes that can replicate the issue below test_list <- list() test01 <- list(a = list(a1 = 1), b = list(b1 = 2, b2 =3)) test02 <- list(a = ...
0 votes
1 answer
11 views

Error while inserting a value from loop into a new column

I am trying to insert the loop value as a new column in the main data.frame . The error I get is it inserts only the first time and the rest of the values in the same loop is blank. data <- data....
  • 1,293
0 votes
0 answers
19 views

How to eliminate special characters for beginners

I need to preface this by saying that I am a complete beginner to using R/Posit products so I am sorry if I seem very dumb. I am conducting a text analysis where I am cleaning up data that includes ...
0 votes
0 answers
16 views

How to make data in Shiny modal consistently update before rendering

I'm trying to make the data in my R Shiny app modal (output$selected_table and output$selected_details) always refresh before rendering. My attempt in the app below sometimes works, but often doesn't, ...
  • 515
4 votes
0 answers
41 views

How are size= and linewidth= related in ggplot2

I am not understanding the relationships between size= and linewidth= in points, lines, and text in ggplot2. Below I try to demonstrate my confusion. In this tidyverse documentation about aesthetic ...
  • 377
0 votes
0 answers
25 views

Extract different hashtags "#" from a text stored in a Dataframe with the R language

I have a data frame with some tweets and i want to extract the hashtags from the tweets using the unnest_tokens() function of tidytext package , creating a tokenized data frame with one row per ...
7 votes
1 answer
57 views

How can I write a `%*%` method for a base matrix S3 subclass?

I'd like to write a %*% method for a base matrix subclass. My subclass is an S3 class and the documentation of help("%*%") says that %*% is a S4 generic. I've written methods for S3 ...
  • 394
0 votes
0 answers
16 views

Unable to read in full table with rvest

I'm new to webscraping and I'm trying to read in the full table at https://www.fantasypros.com/daily-fantasy/mlb/draftkings-salary-changes.php. However it only returns a table with 1486 values, ...
  • 1
1 vote
2 answers
38 views

How do you pivot_wider multiple paired variables with NAs?

I just have a truncated and subsetted df with one paired set of 3 variables each that looks like this; structure(list(UID = c("20210521-3", "20210521-1", "20210521-4", &...
  • 173
0 votes
0 answers
7 views

Error:can only bind lists of raw vectors (or null)

I have two data frame x and y. I am trying two merge this two data frame using sqldf function in R. Sqldf::sqldf( select * from x join y on x.key=y.key) But this gives me error Error:can only bind ...
  • 11
1 vote
0 answers
17 views

matrix inside a matrix in R works in console but fails in terminal

This code segment creates train as a subset of matrix x, and it is still a matrix. What I don't understand is why using it to index the x matrix in the cv.glmnet statement in the segment below ...
0 votes
0 answers
10 views

Intercept in fixed effects regression with feols

How do I get the intercept from a fixed effects regression using fixest::feols? library(fixest) feols(Sepal.Length ~ Sepal.Width | Species, iris) #> Estimate Std. Error t value Pr(>...
-1 votes
0 answers
12 views

How do I represent features with multiple values for one datapoint?

I am building a model and have features that have multiple values and I'm at a loss for how to represent it. For example, if I'm trying to predict the price of a t-shirt and I have a feature "...
0 votes
0 answers
10 views

City to Census tract mapping

I am trying to get a mapping of "all cities of United States" to Census tracts. I know that it wont be perfect, there can be cases of one to many and many to one, however it will still be ...
0 votes
0 answers
10 views

RIS files suddenly uploading irregularly to R studio?

I've been uploading RIS files to R studio frequently as part of a systematic review. Typically when I upload these files (exporting with full records from Web of Science to EndNote), the result is a ...
0 votes
0 answers
9 views

Time average from netCDF in 4 dimensions

i'm a master degree student in marine biology, and i'm new in the R world. I would really appreciate your help. In short, I downloaded from the Copernicous repository a set of ocean environmental ...
0 votes
0 answers
24 views

Check if each string in one column occurs anywhere in another column in R

I am working with 2 datasets in R. Let's call them df_a and df_b. df_a contains a column, let's call it "name", with string values, both official and unofficial. df_b also contains a column, ...
0 votes
0 answers
9 views

Error in xfun::normalize_path(path, ..., must_work = must_work, resolve_symlink = FALSE)

I am trying to run the file that comes by default from an Rmarkdown, however I get this error What I've tried so far: Uninstall old versions of R; Install version 4.2.3 of R and install Rstudio; I ...
0 votes
1 answer
23 views

How to add 'apply' function to calculate multiple 95th percentile?

I have 50 items from column 1 to 50. And I would like to calculate 95th percentile for each item to replace the outliers. I found the quantile function for calcuating specific percentile, quantile(...
0 votes
1 answer
23 views

Reorder geom_bar() bars by count within a for loop

Sample data: df <- structure(list(Gender = structure(c(3L, 1L, 3L, 1L, 3L, 3L, 1L, 3L, 1L, 3L, 1L), levels = c("Man", "Other", "Woman&...
  • 700
-1 votes
0 answers
16 views

Web scraping a specific website for car ad data using Python or R [closed]

I'm trying to extract data from the website https://www.sauto.cz/inzerce/osobni/skoda?stav=ojete, which contains around 18,000 ads for used Škoda cars. My goal is to extract specific information from ...
0 votes
1 answer
28 views

Training a neural network model in neuralnet package in R taking days and not finished yet

I have constructed a model in R (R Studio) for a neural network with two hidden layers using the neuralnet package. It is already 3 non-stop days but the model is not trained. All I see is the usual ...
0 votes
0 answers
12 views

how to remove certain elements from sqlite model file and store each deletion in a separate sqlite file

I have a sqlite model file.I want to delete 128 rows from it but store the final into separate model file. So like for 1 row deleted save the remaining rows or data in a new mode file. and for another ...
0 votes
0 answers
19 views

Ordinal Logistic Regression Error in svd(X) : infinite or missing values in 'x'

I am trying to use an ordinal logistic regression model that predicts length of stay (los) which I converted to an ordered factor using total payment amount (total_payment_amount) and insurance ...
0 votes
0 answers
25 views

Changing color based on categorical variable in a ggplot loop [duplicate]

I am trying to change the line color in the plots based on the categorical variable "Colonizers". The plots display the legend with the appropriate level but the color is the same for all ...
0 votes
0 answers
15 views

How to download zipped (.gz) NCBI Gene DATA form website directly into R

I am in need of help with downloading and handling data from NCBI. The problem starts with the "hit results" file downloaded from NCBI Blastn that only have genes identified as refseq and/...
  • 51
0 votes
0 answers
5 views

Defining custom items in the contextMenu for rhandsontable in R

I am trying to define custom items in the contextMenu for rhandsontable in R, following the Handsontable documentation. However, I am encountering an error. Here's the code I have tried: library(...
  • 2,336
0 votes
0 answers
16 views

How do I filter multiple things? [closed]

i have a dataset with car manufacturers and models. I need to filter Nissan from the manufacturers and just see the nissan models. HELP!! I have tried group_by and filter(manufacturer==nissan)
0 votes
1 answer
22 views

How do I merge files from separate directories in R?

I have a folder called simulations that contains 100 sub-folders, each of which contains the results of simulations. The results of each simulation in each sub-folder are in four separate files named, ...
  • 473
1 vote
1 answer
23 views

R DBI::dbGetQuery where clause interprets string as a column name

RStudio, packages DBI and odbc, connection to Amazon Redshift. I need the records of retirees from a leavers table. If I use a where clause like this: leavers <- dbGetQuery(con, 'select distinct ...
1 vote
3 answers
29 views

How to convert a wide format data with multiple categorical variables to long format in R?

Here is my initial data. df <- data.frame(v1 = c("a", "a", "a", "a", "a", "a"), v5 = c("c1", "c2", ...
  • 21
0 votes
0 answers
32 views

Vectorizing S4 Class in R

I am trying to compute a log-likelihood, where the likelihood is a convolution of two distributions, and the distribution parameters depend on the value of that data point. More formally, I believe ...
0 votes
2 answers
25 views

How to order a dataframe using the order of the another to make matches between lines in R

I want to check if there are changes between rows, but the people are in different order and I want to have it in the same exact order. This is an example of the data in the original database: ...
1 vote
1 answer
26 views

pass values through to piped dplyr verb inside if{} statement in function

Say I have this data: d <- msleep %>% mutate(comfort_color_desk = sample(c(0,1), replace=TRUE, size=nrow(msleep)), comfort_color_chair = sample(c(0,1), replace=TRUE, size=...
  • 971
1 vote
1 answer
17 views

file.choose() opens dialogue without file names on Windows

When I use file.choose or choose.files to select a file, the dialogue window shows folder icons but no text. This problem did not occur previously. I did update RStudio not too long ago, but I am not ...
1 vote
1 answer
21 views

Extract attributes from objects in a list and write them into a dataframe

I have a list of objects (outputs of survey::svyciprop) and I am trying to extract their attributes to create a data frame with all of the results. #example of an object props_and_cis[[1]] ...
0 votes
0 answers
12 views

nested parallelism with r future

I'm trying to read multiple large csv files with nested parallelism with future. I have a single machine with 32 cores, and I want to set up nested parallel (5 by 6) with outer 5 process with 6 cores ...
3 votes
4 answers
40 views

Insert string in vector before every string containing pattern

I have the following vector: test <- c("here is some text", "here is some other text", "here is my formula", "2+2", "here is my second formula", &...
  • 384
0 votes
0 answers
16 views

When trying to use predict in r I keep getting an error [closed]

Im trying to use predict() in R, but I keep getting the error Error in data.frame(Education = Graduate, Years_of_Experience = 3) : object 'Graduate' not found Here is my code: dataQ3 <- read.csv(&...
1 vote
1 answer
14 views

How can I perform multiple linear models by accumulating the groups in R?

I have a database with stable isotope measurements: deuterium and oxygen_18. Year Deuterium Oxygen_18 2005 -28 -4.6 2005 -27 -4 2005 -47 -6.1 2005 -28 -3.8 2005 -54 -7.2 2005 -...
0 votes
0 answers
30 views

How to merge files in a directory with r? (using Multmerge() function)

I am a 2nd year PhD student who is having trouble with some code in R. I have a folder with 10 excel sheets. I want to merge those excel sheets so I'm using the code below: Unit3 = multmerge("~/...
  • 1
1 vote
1 answer
46 views

ggplot giving decimal values in legend while the column has numeric values

plt <- ggplot(data=a,mapping=aes(x=distance, y=rate)) + geom_point(aes(size=as.numeric(`Number of years of data`),color=Trend)) The column "Number of years of data has values 17 and 18 ...
0 votes
3 answers
29 views

How can I take repeating rows and transform the data frame to add columns of unique identifiers in R?

I have a very large data frame. In simple form it would look like this... df <- data.frame(matrix(nrow = 20, ncol = 2)) df[1:10,1] <- c("HeaderStart","LevelName","...
  • 135
0 votes
1 answer
28 views

Correlogram with Question Marks Along the Diagonal

I did a correlation analysis in R and have a correlation matrix with only the p-values. I created the correlogram for only the significant p-values(<0.05) using this p-values matrix. However, my ...
  • 29

1
2 3 4 5
9722