Episode #125 of the Stack Overflow podcast is here. We talk Tilde Club and mechanical keyboards. Listen now

Questions tagged [r]

R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization, and general computing. Please provide minimal and reproducible example(s) along with the desired output. Use `dput()` for data and specify all non-base packages with `library()` calls. Do not embed pictures for data or code, use indented code blocks instead. For statistics related questions, use https://stats.stackexchange.com.

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

Subtract columns [i] row from very last row in r

I am currently working with Monthly data. I have 10 columns and 200 rows. I want to subtract each consecutive row from the very last row in r. Is there a way to do this for all columns in a simple ...
0
votes
0answers
10 views

Any smart way or package in R for extracting mail bodys from emails?

I have a data frame, including one column of emails. one value in this column is a email chain. For example, one of them is: a <- '<P>Dear aaa,</P>\r\n<P>&nbsp;</P>\r\n&...
0
votes
1answer
13 views

Find row number based on value r

How do you find the row numbers associated with a specific text string? I need the function to return [1] 1 2 3 4 from the dataset below. RowNumber Name 1 Diet Pepsi 2 Pepsi Max 3 Diet Pepsi 20 ...
1
vote
1answer
19 views

Suppose the name of a column in a dataframe is unknown to me, how can I sort the df according to the values in that column?

I'm trying to sort a dataframe in descending order according to the values in a specific column whose name is supposed to be unknown to me (i.e. I know it but I am not allowed to use it). The only ...
0
votes
0answers
12 views

Forced network diagram in R

I am building a forced network diagram using the networkD3 R package, and am having issues getting the network to display. I can use the "simpleNetwork" function just fine, but not the "...
1
vote
0answers
11 views

I have a joint PMF in matrix form. How to use R to find $P(N > G)$?

I've just started learning R, and I'm attempting to do some calculations involving a joint PMF in R. The following matrix holds the joint PMF $p_{NG}(n,g)$: (pNG <- matrix(c(16, 0, 0, 0, 0, 8, 8,...
0
votes
0answers
18 views

Calculating the Mean of Groups of 4 in R

I have 7 columns and 184 rows. Column 1 is the month where row 1 is month 1 through month 184. Column 2:7 is pricing data, where numbers are all under 100. What I am trying to do is aggregate rows in ...
0
votes
0answers
13 views

Loop through each timestep in NETCDF file R

I am processing some big data files using a modified version (below) of the code at a github repos. Unfortunately I do not have a reproducible example to support the question, but I can describe what ...
0
votes
0answers
15 views

Change output from Clipboard on Paste

I frequently have to copy file paths from Windows 10 programs or dialogue boxes into my R code. Since R escapes backslashes, I always have to change the backslashes to forward slashes or double ...
1
vote
1answer
24 views

how to apply the same transformation to all files in a folder

I am new to R I have 1200 gene expression files with only two columns gene name and gene expression value I am looking to filter out 63 of these genes and generate a gene file with only the gene ...
0
votes
0answers
17 views

R: function to compare the distance between multiple gographic coordinates

I have two data frames. The first contains all the points I want to classify with the name of the nearest newyork neighborhood. The second data frame contains neighborhood names and their centroids. ...
0
votes
0answers
6 views

How to check the PH Assumptions for many univariate Cox regression models at once?

How do I check whether or not the results by the following univariate analyses hold true? (I'm looking for a function similar to the cox.zph used to check PH assumptions for multi-variable Cox ...
0
votes
0answers
12 views

Problematic gganimate messages when producing an .RmD file as a post on an already existing wordpress website

I have a Wordpress website for my podcast, www.ghccpod.com, and have produced an r-markdown script for it. I try to render it using RWordPress and knit2wp, but the out of the file has several issues, ...
0
votes
1answer
26 views

How to merge unstructured columns into one full table using R

I have excel file looks like this: excel_DF 1 time Open 2 1PM 0.224 3 2PM 0.226 4 3PM 0.523 5 4PM 0.121 6 5PM 0.121 7 8 9 ...
-1
votes
1answer
34 views

set up a diagonal matrix faster?

Calling diag(x) is apparently very slow. Is there not a faster way to set up a diagonal matrix? It seems like a fairly easy operation, yet R takes forever. Also, using the diagonal matrix later on in ...
0
votes
0answers
27 views

Can you list an exception to tidyselect `everything()`

library(tidyverse) iris %>% as_tibble() %>% select(everything()) #> # A tibble: 150 x 5 #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> <dbl> &...
0
votes
0answers
12 views

Is there a way to combine mosaic plots using different data sets so that they are outputted next to each other?

I am trying to combine 20 mosaic plots onto one output. par(mfrow=...) is not working. I would like the rows to have 3 plots in each row. Here is code for just 4 of the plots that I am using: ...
0
votes
0answers
4 views

How to work with Formal class HDB in R, how to search the database directories and query them?

I am quite new to establishing and working with connections in R. Perhaps I am totally off but is there a way to query specific sub directories/ variables from the established connection. My ...
1
vote
1answer
17 views

How to link checkboxInputs without using radioButtons in Shiny?

I am trying to create two checkboxInputs in an R Shiny app which behave in a way that only one can be enabled at a time but having neither enabled should also be an option (essentially they both can't ...
0
votes
0answers
5 views

GARCH, Value at Risk, Student´s t and Skewed t, rugarch package

I would be very grateful if someone can help me to clarify some doubts about GARCH from rugarch package, conditional distribution and VaR. I´m computing VaR with student t and skewed t distribution. ...
0
votes
0answers
5 views

Image returned from package gapfill different than raster plot

The Image function from package gapfill (gapfill::Image) returns a plot that looks different than the raster layer associated with it. Is it because the input of Image is an array and this makes the ...
0
votes
0answers
14 views

Getting accented characters recognized when building a custom stopwords lexicon in R

I'm building a custom stopwords lexicon in R to remove accented characters. I thought that using the unicode reference would enable this, but it doesn't work and I'm having trouble thinking off ...
0
votes
0answers
8 views

automatically testing a list of variables for a ks.test within code

I am running ks.tests on a long list of variables (about 15) in univariate and multivariate analysis. the goal of my analysis is to assess memory performance in different high and low risk categories ...
0
votes
0answers
12 views

How to read in an xls file after using unzip() to place it into a temporary folder?

I receive weekly emails from a database as zip files. In the zip file is a single xls file. When I use unzip() and place the xls file into a designated shared network directory, I cannot use any xls ...
0
votes
1answer
15 views

How to compute CJ by groups faster? (data.table's Cross Join)

I need to use a large dataset to compute (many times) a Cross Join by groups, and it's quite slow. Could you tell me any faster way to do it? Toy example: set.seed(1) totletter <- 10 LLL <- ...
0
votes
0answers
11 views

Add borders and/or leave spaces for R Shiny Dashboardheader, Tabpanel, etc

Due to the design of my app, I would like to give some spaces between each shiny items. In particular, I would like to learn the following: How to add a color border between the shiny dashboardheader ...
0
votes
1answer
19 views

R: Sorting all columns in data frame by an alphanumeric column

I want to sort all columns of a data frame in R by a column containing alphanumeric data. Here is an example data frame: R> dd <- data.frame(b = c("Hi", "Med", "Hi", "Low"), x ...
0
votes
0answers
16 views

Trying to unnest broom::augment data, but R “can't cast”

I can't reproduce the data here, but I'm hoping I'm making an obvious mistake. I am trying to get residuals from all the of the models I fit with purrr::map. My code looks like this: df %>% ...
0
votes
2answers
36 views

R: How to get an object inside list using get() or mget()?

I have a list mylist with named objects in it. Say one of them is called a. How do I get a from outside the list assuming the name of the list is unknown? I want to be able to say get("a") and get ...
0
votes
2answers
23 views

r convert raster stack or brick to an animation

I have downloaded some NetCDF files of land use scenario results from http://luh.umd.edu/data.shtml. Each file at this location has values for 11 land use types with annual values from 2015 to 2100. ...
0
votes
0answers
5 views

how to define initial values to be optimized in Panel Smooth Transition Regression (PSTR) modelling?

In the example given by R with Hanssen99 data, When you determine which transition variable to use for the estimation, in this case “inva”, you can estimate the PSTR model: pstr = EstPSTR(use=pstr,im=...
2
votes
2answers
28 views

Add a count column and count twice if a certain condition is met

I am wondering if there is a way to make a conditional column-count by a group, adding 1 to a row_number or rowid if a certain value is met (in this case 0). For example: df<-data.frame(group=c(1, ...
0
votes
1answer
10 views

rpy2: handling nested data.tables from R

I have R nested data.table of the format: Date Values 2019-10-11 <data.table> 2019-10-12 <data.table> Each of the Values in the above data.table are <data.table> ...
1
vote
2answers
26 views

Match/subset one dataframe based on conditional values in another dataframe in R

I have two data frames: df1=data.frame(A=c(1,2,4,8), B=c(4,3,2,9), C=c(10,11,1,2), D=c(12,40,3,4)) df2=data.frame(A=c(0.5,2.0,0.1,0.3), B=c(1.5,0.5,0.2,0.1), C=c(3.0,1.25,0.5,0.2), D=c(0.7,0.8,0.2,2....
1
vote
0answers
11 views

How to update a JSON file from R Shiny?

I have this code: # Preloads ---- library(shiny) library(dplyr) library(xlsx) library(jsonlite) library(httr) library(svDialogs) library(downloader) params <- readLines("params.json") # end ...
1
vote
2answers
19 views

How to add a row to a dataframe and avoid “non-numeric argument to binary operator”

I have a dataframe. I want to normalize columns 2 and 3 by dividing them by the maximum value of column 2 and 3. > testdf<- data.frame("a"=c("b",2), "b"=2:3, "c"=3:4, "d"=4:5, stringsAsFactors ...
0
votes
0answers
12 views

Using Caret to Do Linear Prediction

I want to use Caret to do prediction(Predict the electricity usage). I want to get the actually electricity usage, but the prediction alkways give me 1. I want to predict the column of '...
0
votes
0answers
6 views

Function with openxlsx works on R console but fails in Shiny

I'm trying to write a function to wrap up some data frames for export to Excel using the openxlsx package. It fails when running from a downloadHandler function in a Shiny app, but runs fine on the ...
0
votes
0answers
19 views

Scheduling an R Script

My team and I are using a .bat file @echo off "C:\Program Files\RStudio\bin\rstudio.exe" R CMD BATCH --vanilla --slave "C:\Users(user name)\Hello.R" to execute a script that reads... print("Hello ...
-3
votes
1answer
27 views

For every category I want to make numeric calculations

I want to add a column in r to calculate the difference of scores for every equal characters in the same column (e.g:names) I tried to group the data using group_by function in dplyr but it didn't ...
1
vote
1answer
12 views

predict values from GAM for grouped dataframe in R

I have a dataset of mean annual temperature values at different latitudes in different years. I want to use this to predict the latitude at which a given temperature could be found in a given year; i....
0
votes
0answers
20 views

Continuous calculation Based on Previous and Next Record in R

I have a data table such as: odo lat 2.62 30.20 5.19 7.61 18.82 19.06 40.10 19.35 20.54 20.81 70.90 ...
-1
votes
0answers
17 views

R Box plot error. Y axis values not printed

BOX PLOT The values in the y axis are not printed in a proper format. I don't know if i have to set the range or something. Help would be appreciated Image attached library(tidyverse) library(...
-3
votes
0answers
17 views

R programming. How do I delete a row based on a column input

I am working with a data frame df in R. I have a vector of values corresponding to the first column of my data frame. I want to use the vector to remove the row if the column has one of the numbers ...
0
votes
0answers
9 views

How to combine raster layers in R with different extents and which do not overlap

I have 2 RasterStacks. These are parts of one AOI, but were separately downloaded from the Google Earth Engine due to being split on different Sentinel-2 scenes. I cannot combine them in QGIS, since ...
1
vote
1answer
21 views

Wrong column on data.table merge

Let's say I have these two tables: library(data.table) x <- data.table(Date = as.Date(c("1990-01-29", "1990-02-30", "1990-01-31", "1990-02-01", ...
0
votes
0answers
12 views

Change location names to ID's based off second data frame list

I have a two data frames one: Location, agegroup, gender, mon, year CityName1 CityName2 The second: Location, Location ID CityName1, Location1 CityName2, Location2 How, in R, do I replace the ...
0
votes
1answer
20 views

R: Parsing boolean command line argument in using argparse

I am using "argparse" library in R for command line arguments. # Create parser parser = ArgumentParser(description='command line args') # Add command line arguments parser$add_argument("is_local", ...
1
vote
0answers
24 views

Problem with simulation empirical probability [on hold]

I want to do a simulation in r of confidence interval with traditional statistical inference and with Bayesian inference for empirical probability. Tridional statistical inference Firsly let's ...
-2
votes
0answers
21 views

use ggplot find regression equation

Construct a plot (using ggplot) of Price on the y-axis and Living Area on the x-axis and use color for the indicator of fireplaces or not. Draw the regression equations for those with fireplaces and ...