Use Stack Overflow for Teams at work to find answers in a private and secure environment. Get your first 10 users free. .

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
3 views

How to generate randomised distribution maps

I am looking for a way to generate distribution maps in R for virtual entities, by producing a data set of random coordinates points that follow a number of conditions, so that: A) these random point ...
0
votes
0answers
3 views

How to compute total within sum of square in hierarchical clustering

I read several textbook and online tutorials about clustering algorithms. In K-mean algorithm, when you run kmean() the information of total within sum of square is included. But we runhclust()in ...
0
votes
0answers
5 views

R how to extract permutations of all unique factor levels within a list

I have three columns in a data frame in which I want to list all the possible combinations for each column variable: Condition, level and Response. Df <- data.frame( Condition = c(rep("No", 20), ...
0
votes
2answers
17 views

Rename all columns of dataframe by extracting pattern in column name

I have a dataframe about stock-market data and I want to delete a specific pattern from all column names. This is my dataframe: ADS.DE.Open ADS.DE.High ADS.DE.Low ADS.DE.Close ADS.DE....
0
votes
0answers
7 views

Filter leaflet map which includes clusters using crosstalk

I am working on a dashboard using Flexdashboard and would like to present a map and datatable that filter together using crosstalk. I have been able to do this using standard or circle markers but it ...
0
votes
0answers
10 views

64 bytes keys in PyNaCl

Is there a way to use 64 bytes keys in PyNaCl? I am working with the signature functions in PyNaCl. Where I can sign messages and verify them using asymmetric cryptography. As far as I know the basic ...
1
vote
0answers
12 views

R reticulate importing module in second python file not working

I am having problems with loading modules in a python script which I am calling via reticulate. My file-structure basically looks like this: Rscript.R library(reticulate) py_run_file("python1.py") ...
-3
votes
0answers
23 views

How do I append dataframes from different list into one dataframe using R?

I have a few Lists (User 1, User 2, User 3 etc). In each List, there are 3 dataframes (i.e. Name, Education and Work). How do I use R to append all the 'Name' dataframes from the different List ...
3
votes
3answers
24 views

Expand row given criteria

I would like to insert a duplicate row if a column has a given value. I have the following dataset: dataset <- data.frame(id=c("A","A","A","A","B","B","B","B"), date=c('2018-05-09 11:...
1
vote
2answers
20 views

How to easily rename all the factors in a dataframe in R?

I have renamed all the factor using revalue function from plyr package. However, I thought there might easier way to solve this problem. cleandata <- Eyedata%>% mutate(MediaName = revalue(...
1
vote
0answers
15 views

Combine factor variable levels with less observations together. for all factor variables in a data frame

I am trying to write a function that will look at all the factor variables in a data frame and combine all the levels together but only if a level contains less observations then a certain percentage/...
1
vote
1answer
15 views

Add a legend to time-series data ggplot

I asked a similar question earlier however, the previous code seems unable to solve my problem. Specifically I want to add a legend to my plot below. I want the darkred line to be named as "Cluster 1"...
1
vote
3answers
29 views

Dataframe merge rows

I have the following dataframe in R my_df <- data.frame(V1 = c(1,2,3,1), V2 = c("A","B","C","A"), V3 = c("S1", "S1", "S1", "S2"), V4 = c("x","x","x","x"), V5 = c("y","y","y","y"), V6 =c("A", "B", "...
0
votes
2answers
18 views

How to count the number of instances where the wind directions is > (-3.54) for >= 5 consecutive days in a season

I have a data set of U wind direction recorded every day from 1993 to 2016. I would like to know how many instances there are in a season (let's say Autumn; from March to May) where U is <(-3.54) ...
0
votes
0answers
11 views

How to use downloadHandler for the download button create inside shiny datatable?

I created download button inside each row of shiny datatable as shown here. The table is inside one of the shiny module. I wonder which id should be attached to output while using downloadHandler for ...
1
vote
1answer
16 views

What is the easiest way to get the default R sf map plot default legend back?

I have been trying to display a legend on a choropleth plot but finding the R docuemntation for legend a bit difficult to get my head around. Been reading it for a few hours now. I see that the ...
0
votes
0answers
10 views

Software recommendation for circos plot with discrete axis

I would like to make a circos-like plot to visualize SNPs only (with multiple tracks for SNPs attributes). It could be done either with python, R or I am happy to consider other languages. So far, I ...
1
vote
3answers
26 views

How to transform wide data to long data by multi-columns

How can I transform data X to Y as in X = data.frame( ID = c('A','A','A','B','B','C','C','C'), V1 = c(2.3,2.6,2.9,3.0,3.2,1.8,1.7,1.6), V2=c(5.5,4.7,5.0,4.4,4.2,8.0,9.0,8.5), V3=c(1,1,3,2,2,3,...
0
votes
0answers
17 views

Encoding issues with R and Tibco

We have around 4 R scripts embedded in a master R script (which calls all the scripts). If we run this R script from the command prompt using all the args required for that job, its running fine and ...
0
votes
1answer
14 views

Rscript file path with space on windows batch file

I have Google Drive folder saved in my windows. I have created the bat file in that folder to run R through task scheduler but it's not reading the file as there is a space inbetween Google Drive. @...
0
votes
1answer
18 views

Confidence interval of episode duration frequencies

I have the episode duration data (in days) dur<-c(1, 2, 1, 2, 1, 3, 11, 2, 2, 3, 2, 4, 1, 2, 2, 1, 2, 10, 1, 1, 2, 2, 18, 2, 2, 2, 1, 7, 1, 1, 11, 25, 17, 2, 2, 9, 3, 3, 2, 5, 3, 2, 3, 2, 5, 363, ...
0
votes
0answers
9 views

Comparing two distributions in a spatially autocorrelated grid

I have a circular grid separated in 8 juxtaposed quadrants. In each quadrant I have the abundance of two species. The abundances in each quadrants are correlated to the abundances in the nearest ...
1
vote
1answer
18 views

R shiny dashboard Leaflet pop-up grey background

I am quit new to R and trying to develop a dashboard with Shiny. I am adding a datatable, and this is working well. I have manage to create a popup when clicking on a record. The popup shows a ...
1
vote
0answers
27 views

customize background color of selectInput in shiny

consider the following simple shiny app: ui <- fluidPage(tags$head(includeCSS("www/mycss.css")), selectInput("foo", "Choose", width = '20%', multiple = F, selected = "red1", ...
0
votes
0answers
10 views

flex_dashboard shiny_prerendered with eventReactive filtering

I am trying to build a data heavy, calculation heavy shiny flex_dashboard with runtime: shiny_prerendered. I would like all calculation and filtering be done on the server side and the rendering on ...
0
votes
1answer
16 views

Formatting data output to get numeric variables to always show 2 decmial places

I am running the following code to summarise a variable in r setDT(RWA_Cleansed_Data)[, .(value=sum(ACCOUNT_BALANCE), freq = .N) , by = PERIOD ] The output is PERIOD value freq 1: ...
1
vote
0answers
17 views

Any method of R to increasing the execution speed for stopwords in R?

I'm actually looking for a speeding up my execution speed for my R script. I've a data set which I call refdata with 127155 rows and mapdata with 2013 rows and I also merge the data and calls it "...
1
vote
1answer
20 views

How to fix combine plot in R

I'm doing the heart function in R. I wrote it down and the plot doesn't show whole function in cordinate-axis. x<-seq(-1,1,0.001) length(x) m<-c(abs(x)^1/2) n<-c((1-x^2)^1/2) y1<-c(m+n) ...
2
votes
2answers
36 views

How to calculate a new column using individual values of other columns in a formula?

I have a data frame with one column X that looks like this: X 1 8 2 4 3 2 4 5 5 3 6 2 7 1 8 5 Using the values in this column I want to create a new column Z that uses the ...
0
votes
2answers
23 views

Count when the value is different then the next one in a particular row

I want to make a count when a value in a sequence changes.To elaborate if the next value if the row is the same then counter=0 else it should be equal to 1. I am using R. for example if my row is ...
2
votes
1answer
33 views

Vectorising a cross product of vector and matrix with consecutive indices in R

Some context: I have a vector e of dimensions n×1, and a correlation matrix R of n×n. I am trying to efficiently calculate the quantity in R, without looping. So far, I have been able to do it with a ...
0
votes
0answers
21 views

Drawing plots from an existing for loop using a conditional statement

I have a data set with the columns: Site, Year, Date, count, and SpeciesName. I had a homework question that stated: "In some years, counts were performed twice at each site. For those years, find the ...
0
votes
0answers
8 views

Event study in R as robustness check for difference-in-regression discontinuity design

I would like to run an event study regression in R using my panel dataset. This would serve as a type of robustness check for my research design, which uses a difference-in-regression discontinuity ...
0
votes
0answers
15 views

Get Latest Rows by Date and Name [duplicate]

I have a DataFrame named "iceland" with 3 relevant columns: "date, name, points", which is already sorted ascending after date: p.E.: # date name points 1. 2.5.2006 Bob 3 2. 5.7....
0
votes
1answer
18 views

Percentage of values above the 99th percentile

How can I compute the sum of values that is above the 99th percentile. And then divide it by the total values to get the percentage of values above the 99th percentile. For example dataset mtcars >...
1
vote
1answer
18 views

Creating intervals of 5 seconds for data and grouping them

I have a dataframe with one column being time and the other column being price. it looks like this Time | Price 15:31:01 | 2 15:31:03 | 4 15:31:05 | 3 15:31:08 | 1 15:31:10 | 9 I would like to ...
0
votes
2answers
24 views

R - rbind multiple dataframes in list based on pattern in dataframe name

I have a list of dataframes (list) with the following names names(list) <- c("prefix-001A","prefix-01B","prefix-001C","prefix-002A","prefix02B") I want to create a new list of data frames with ...
0
votes
0answers
13 views

Save data based on RShiny selection with varying row lengths in a single workbook

I am having a simple RShiny dashboard where I am loading the data, which contain sales figures of some items(materials). Sales are split column-wise, that means each 'month-year' identifier is one ...
0
votes
2answers
23 views

How to sample according to a long array of probabilities of being True in R?

N <- 1000 arr_p_True <- runif(N) arr_simulated <- sapply(arr_p_True, function(p) { sample(c(T, F), 1, prob = c(p, 1 - p)) }) arr_p_True is what I want to get, but with very large N this is ...
2
votes
0answers
24 views

ECDF plot in ggplot2 without expanding count variable

I have a dataframe which looks like Height Count 173 2 184 3 193 1 Usually, to plot an empirical cumulative distribution function, one: 1) expands the dataframe by using e.g. ...
0
votes
1answer
17 views

Score new deployment data using XGB model

Background I've built an Extreme Gradient Boosting (XGB) model using R I've used the model object to score my test set But, I'm unable to use the model object to score my deployment set Load R ...
0
votes
0answers
15 views

Change name of groups in bal.plot

I am trying to visualize results from matchit procedure with bal.plot() from coblat package. It works just fine, except I would like to change the lables for the group which by default are "...
0
votes
2answers
26 views

Count values per rows in a data frame R

I know, there is other questions like this one but none of them answer my specific problem. On my data frame, I need to count the number of values in each rows between cols 3 and 8. I want a simple ...
0
votes
0answers
21 views

How to “stitch” two vectors together in R? [duplicate]

If I have two vectors v1 = c(1, 2, 3) v2 = c(4, 5, 6) and I'd like to combine them into v3 [1] 1 4 2 5 3 6 Is there a simple function to do this, or should I do it manually?
1
vote
3answers
28 views

split columns by character in list of data frames

I have the following list of data frames: df1 <- data.frame(x = 1:3, y=c("1,2","1,2,3","1,5")) df2 <- data.frame(x = 4:6, y=c("1,2","1,4","1,6,7,8")) filelist <- list(df1,df2) > filelist ...
0
votes
1answer
27 views

Using tidyr, when spread values get NA

I have a problem, I have used tidyr to try to convert data, both from long to wide and wide to long. All functions as gather, unite works fine, but when I apply spread I get the right format but a big ...
0
votes
0answers
20 views

How to put condition in concatenation of columns

I wanted to concatenate two columns whereby one column is numeric and the other one is character specifically, quality sign (+/-). Below is example: test <- data.frame(cbind(c(4,-5,6),c("-","-","-"...
0
votes
0answers
13 views

Add marker on leaflet when selecting from filter in flexdashboard for R

I am quit new to R and trying to develop an dashboard with Flexdashboard based on this example: https://matt-dray.github.io/earl18-crosstalk/04_leaflet-flexdash-dt-crosstalk.html I get it to work, ...
0
votes
0answers
12 views

How can I select the maximum value for each position from two stacked transitionLayers in R?

In order to conduct least cost analyses in R, I am trying to produce the cost surface from a DEM. I want to treat land areas in a different way from sea areas (sea costs being half of land travel ...
0
votes
1answer
18 views

R - Anova not working at multilevel analysis - “$ operator not defined for this S4 class”

I got a problem running my code in R when trying to do an anova related to my multilevel analysis. I always get the error: "$ operator not defined for this S4 class". Any help is highly appreciated! #...