Optimize calls to mutate and summarise?
I have this R script:rm(list = ls()) library(tidyr) suppressWarnings(library(dplyr)) outFile = "zFinal.lua" cat("\014\n") cat(file = outFile, sep = "") filea <- read.csv("csva.csv", strip.white =...
View ArticleHow can I run a script on multiple folders
I developed a script to do operations and graphics on temperature and precipitation files and forecasts. I have 3 stations on which I will have to do the same steps, here is a part of the script that...
View ArticleR Matrix class (not base matrix) indexing slow? [duplicate]
I am working with large matrices (~100k x 10k), some of which are dense, some of which are sparse. I am trying to use the Matrix class matrices as those implement a variety of types. However, one...
View ArticleReading a .txt file in R
I'm having trouble thinking about the approach on reading a text file. I initially had a PDF file (700 pages worth of table formatted same exact way) which I then converted to a .txt file using the...
View ArticleMerge different number of columns in R
I am attempting to merge two or more columns in an automated way in some survey data. Example data:data <- data.frame("Q1: What is your gender?" = c("Male","Male",NA,NA,"Male"), "Q1: What is your...
View ArticleHow to create a function based on these process
I have multiple Mplus CFA model outputs (cfa.out) from MplusAutomation. I want to create a R function based on these procedure. Can anyone guide me how to write a function in R? All the process will be...
View ArticlePlotting 3 Variables on One Chart - ggplot
I have some experience with base R but am trying to learn tidyverse and ggplot. I have a dataframe with 4 columns of data. I want a simple x-y plot, where the first column of data is on the x-axis, and...
View ArticleStargazer producing various latex errors
I am using stargazer to output regression results from r to latex. When I run the output in latex I see the results, but get many Package array errors. Here is my code. In R I use stargazer as...
View Articleinstalling a package from private gitlab server on windows
I am struggling with installing a package from a gitlab repository on a windows computer.I found different hints but still have problems to install my package from gitlab. First of all, I generated a...
View ArticleIs it possible to update a BSTS model?
I am working with time-series data which updates daily. Therefore, I thought that the Bayesian framework would fit perfectly because theoretically, it is possible to update the model as new data comes...
View ArticleFast calculation of CDF / rolling join on multiple columns
I'm trying to measure the empirical cumulative distribution of some data in a multivariate setting. That is, given a dataset likelibrary(data.table) # v 1.9.7 set.seed(2016) dt <-...
View Articleimplementing an ignore_year argument in a function
I have a function called date_has_passed where it takes in both a Date-type value and a boolean value as its two arguments. Based on the given date, it calculates the difference between that date and...
View ArticleR function for obtaining a reference to a variable
In Advanced R, environments are advertised as a useful way to get pass-by-reference semantics in R: instead of passing a list, which gets copied, I can pass an environment, which is not. This is useful...
View ArticleUploading many files in Shiny
I am developing an app that helps to organize and visualize many PDF documents by topic/theme. I can upload and read a single PDF but I have difficulty in reading multiple PDF documents.For single PDF...
View ArticleRaster: Extract center of raster images (geoTIFF) and draw its borders
I've like to extract coordinates (and create a data frame) of the center of 4 raster sub-images in geoTIFF and draw the border of 2 selected sub-images, originally split in the r2 image, for this I...
View ArticleReplace cell values, match list elements and switch the pair
I have a list of duplicates l1 <- list(c("a","b"), c("1","2"),c("x","y")). There is also a dataframe as such: df <- structure(list(names = structure(c(2L, 1L, 3L, 4L), .Label = c("1", "a", "x",...
View ArticleIn a data frame I want to duplicate rows with a certain condition in another...
I want to duplicate all rows with treatment C 3 times. How do I do that?A <- sample(1:100,9) B <- sample(1:100,9) trt <- rep(c("A", "B", "C"),3) df <- data.frame(trt, A, B) > df trt A B...
View Articlewrangling a presents/absents table to long form in r
I an new to R (and think I always be). I am trying to wrangle the table resulting this code (only a very short example):PlotA<-c(0,1,0,1,0,1,0,1,0,1) PlotB<-c(0,0,1,1,0,0,1,1,0,0)...
View ArticleExport a list into a CSV or TXT file in R
I'm sorry to ask this question. I'm very noob with R. I know there is a lot of threads which are related to the very same problem. I understood that we cannot export a table if one of its elements is a...
View ArticleSuccessive nearest neighbors in R
I have n data points in a data frame that includes X and Y coordinates. I'd like to take any point (hereafter the first point), find its nearest neighbor (i.e. the second point), then find the nearest...
View Article