Replace column with the most recently available data (replace nested forloop...
Translating nested STATA forloops into R tidyverse/purrr syntaxI am trying to do this using foreach or purrr, but I keep getting stuck.STATA Code:foreach v in zip income child{ g `v`_agg="" **generate...
View ArticleHow to subtract two comma separated columns in R?
I have a small problem that I can't seem to solve. Given two columns:dt <- data.table(ColumnA = c("A,B,C,A,A,A", "A,B,C"), ColumnB = c("A,C,A", "C")) I would like to "subtract" columnB from columnA,...
View ArticleR script for turning a 3-dimensional .nc file into excel spreadsheet(s?)
I am in desperate need of help. I’m a PhD candidate and unfortunately, the university has essentially closed for the holidays so there aren’t people around to ask for help.So I usually work in...
View Articlefrom CSV to a .txt in json format rstudio
beginner to R here.I have a csv file, key1 key2 key3 key4 key5 key6 value value value value value value value value value value value value value value value etc,I would to convert the csv file into...
View ArticleHow to extract the second part of the string after the backslash in R?
I have a string 'ABC1\001ABCEFCGJS' I want to extract only 001ABCEFCGJS from this string How to do so in R?
View ArticleHow to create pair of vector that are complementary to each other based on...
I have the following source vector:source_vec <- c(1:3) What I want to do is to enumerate the vector by splitting into two when one value is selected the other vector is complementary. Finally,...
View ArticleAre there any good methods to run Rstudio jobs one by one?
Rstudio has recently been added Jobs functionality. It is very useful but in the open-source edition of RStudio, some function are limited. I want to run script files using Job one by one (because of...
View Articlehow to combine two regex with if else using stringr
Problem: Hi all, I have this sample dataframe which has institution names I need to extract:mydf<- data.frame(ID=c('1', '2', '3'), Institution=c('Univ of Space, TX, US', '[Bloggs, J., Smith, T.]...
View ArticleHow do I change the height of picker input in from shinywidget?
I use pickerInput from shinyWidget div(class = "choosechannel", pickerInput(inputId = "choosechannel", label = "business channel", width = "150px", choices = c("In-Branch", "Agency", "Affinity",...
View ArticleIs there a shorter way to use Lag Operators in a Regression in R
I am trying to replicate a regression that I saw in an article:Y_t=a(L) Y_(t-1)Where L is a polynomial in the lag operator and it said that “Lag dependent variable [Lags: 1-24] is entered as...
View ArticlePull sample from dataset with comparable demographics
I'm relatively new to coding and would appreciate any guidance at all! I am trying to pull a random sample of 100 patients per group- mortality/ no mortality-in hopes of comparing them. However, I need...
View Articledplyr tibble() output is truncated in R, how do I show complete output?
library(dplyr) df <- as.data.frame(matrix(0, ncol = 200, nrow = 1)) names(df) <- paste0('col', 1:200) df %>% as_tibble() # A tibble: 1 x 200 #> col1 col2 col3 col4 col5 col6 col7 col8 col9...
View ArticleConverting edgelist (occurance) to incidence matrix for social network
I'm new to R/network analysis, and apologize if this is a stupid question. I'm currently trying to convert an edgelist into a network matrix, where the shared category of a group indicates the presence...
View ArticleOne of the factor's levels is an empty string; how to replace it with...
Data frame AEbySOC contains two columns - factor SOC with character levels and integer count Count:> str(AEbySOC) 'data.frame': 19 obs. of 2 variables: $ SOC : Factor w/ 19 levels "","Blood and...
View ArticleNaming a dataframe like the path
I have a lot of CSV that need to be standardized. I created a dictionary for doing so and so far the function that I have looks like this:inputpath <- ("input") files<- paste0(inputpath, "/",...
View ArticleHow can you center a huxtable?
I've looked around and cannot find the answer to this anywhere in the documentation. When creating a huxtable and knitting it in an R markdown document, there seems to be no way to center the table....
View ArticleR function to create a new column with a value based on whether or not text...
I have a data frame df with 2 columns, x and y. x <- c("ABC", "def", "GHI") y <- c("jkl", "MNO", "pqr") df <- as.data.frame(cbind(x,y), stringsAsFactors = FALSE) I'd like to add a column z,...
View ArticleIs there a way to use the base R rug function when plotting gam predictions...
I have run some gams in r and am in the process of plotting the predicted response on the y axis and predictors on the x. I have used rug() to indicate the amount of data points on all plots with...
View ArticleHow to get classification values in RWeka?
can anybody explain how I get the results of each leave in a decision tree made by J48 from the RWeka package?So for example we have this iris dataset in R: library(RWeka) m1 <- J48(Species ~ .,...
View ArticleHow to select a nested field with bigrquery using dplyr syntax?
I'd like to explore a Google Analytics 360 data with bigrquery using dplyr syntax (rather than SQL), if possible. The gist is that I want to understand user journeys—I'm interested in finding the most...
View Article