How to select R data.table rows based on value in a different table?

R
I have a table of (x,y) points and would like to create a second table that summarizes those points. I would like each row in the summary table to sh...
2 years ago

Maximum Likelihood Estimation for three-parameter Weibull distribution in r

R
I want to estimate the scale, shape and threshold parameters of a 3p Weibull distribution. What I've done so far is the following: Refering to thi...
2 years ago

R gsub multiple conditions

R
I am trying to use gsub on a set of strings that might all vary in the wording slightly; I went to the store last night I went to the park yesterday ...
2 years ago

Calculate groups of rows mean

R
I need to calculate the mean of groups of rows in 10 different data.frames and instead of making a code for each data.frame, I want to do it in only o...
2 years ago

step$anova following stepAIC() not subsettable?

R
I'm trying to run a simple backwards stepwise multiple linear regression in R using the stepAIC function from the MASS package. The model runs fine, b...
2 years ago

Regular expression: matching multiple words

R
I am using regular expressions in R to extract strings from a variable. The variable contains distinct values that look like: MEDIUM /REGULAR INSEAM ...
2 years ago

Create a vector of counts

R
I wanted to create a vector of counts if possible. For example: I have a vector x <- c(3, 0, 2, 0, 0) How can I create a frequency vector for all...
2 years ago

Change row order in a matrix/dataframe

R
I need to change/invert rows in my data frame, not transposing the data but moving the bottom row to the top and so on. If the data frame was: 1 2 3 ...
2 years ago

Leaflet map legend in R Shiny app has doesn't show colors

R
When I try to add a legend to a leaflet map for a leaflet map (using the Leaflet for R package) incorporated into a Shiny app, the legend does not sho...
2 years ago

nansum in R for data.table

R
Let's start with DT1 library(data.table) DT1 <- data.table(c(NA, NA, NA, NA, NA), c(1, 1, 1, 1, NA), c(1, 1, 1...
2 years ago

R Scatterplot, transform values used as label

R
I have a simple dataframe and produce a scatterplot: a <- c(-1,-2,-1.5) b <- c(1,3,2) df <- data.frame(a,b) plot(a , b) Result: I would...
2 years ago

Converting Likert Data to Numeric Across A Data Frame

R
I have a dataset with 90 responses to Likert Items that I would like to convert to numeric values. It is structured like the example here: q6 <- c...
2 years ago

R Loop optimisation/ Loop is way too time consuming

R
The following loop takes ages. Is there any way to this in a more time-efficient way? The following data.table consists of 27 variables and more than ...
2 years ago

Scrolling back through the RStudio console

R
This is just a RStudio interface question: When scrolling back through the console to see my work and outputs I can only scroll back so far. Is there...
2 years ago

Nested foreach and dopar - bootstrapping each row of data frame

R
I have data frames that look similar to this: maindata <- data.frame(cbind(num=c(79,61,62,57), denom=c(162356,170189,164...
2 years ago

rle-like function that catches "run" of adjacent integers

R
I'm pretty sure that you all agree that rle is one of those "gotcha" functions in R. Is there any similar function that can "catch" a "run" of adjacen...
2 years ago

Unique legend for two different aesthetics with ggplot2

R
A very simple question I guess but I couldn't find any answer on it. Let's draw an example dataset with 4 columns. I want to plot two different point...
2 years ago

Binding dataframes with matching country names

R
I have two data frames of country data. df1 has all the countries of the world. df2 has a subset of countries but has the populations in one of its co...
2 years ago

Apply which.min on POSIXct

R
I am trying to find the row-wise minimum from a data frame of POSIXct. But using apply with which.min does not work: df <- data.frame(date1 = as.P...
2 years ago

Matching two list of unequal length

R
I am trying to match the values in 2 lists only where the variable names are the same between list. I would like the result to be a list the length of...
2 years ago