R - keep random rows per group, but different numbers per group
The function sample_n() from package dplyr allows to randomly keep a specific number of rows. Combine with group_by(), you can for instance keep 2 observations per group:mtcars %>% select(vs, drat)...
View ArticleI want to turn column names into an identifying column in R
Hey guys I'm pretty new to R so apologies if this is a dumb question. I have a data frame that looks like this:Gelatin Geltrex Combo Control 1 0.761 0.732 0.557 0.723 2 0.704 0.712 0.764 0.540 3 0.580...
View ArticleSelect and fill random pixels in jpg
Let's say I have a .jpg such as below. Is it possible in R to select say 25% of pixels then produce a a new .jpg with those pixels filled in a given colour. Similar to the following question in matlab...
View ArticleRecursively ensuring tibbles instead of data frames when parsing/manipulating...
I have to deal with JSON documents that contain nested documents and at some level have an array which in turn contains individual documents that conceptionally would map back to "data frame rows" when...
View ArticleIs there an R package with a neural net fitting and update function for...
For a project in the fields of Reinforcement Learning for a small gridworld-example with a lot of simulated episodes I want to do the following in R:0a. As a burn-in I simulate 1000 episodes with a...
View ArticleStop submitted lines of code from running
I'm running a long R script, which takes 2 or 3 days to finish. I accidentally run another script, which, if it works as R usually does, will go in some queue and R will run it as soon as the first...
View ArticleOutputting a vector with repeated values
To keep my script records clean, I'd like to output vector inputs with rep() instead of repeated values in chain. Please see my example below, using dput():v<-c(rep(1,2), rep(2,4), rep(NA,5))...
View ArticleExtract elements from list with non-exact match in R [duplicate]
This question already has an answer here:Find the words in list of strings 1 answerI would like to identify whether there are common elements between two different list of compounds.I successfully used...
View ArticleCustomize Legend with discrete Ddta
I have a data whose value ranges between (Min = -3.686638e+18, Max= 1.647103e+17). I want a plot where the values below zero (0) should be shown in one color while the values above zero (0) to...
View ArticleTrying to find a way to combine IRT info plots from 3 different mirt models...
I am looking to combine all three" test information function" lines (one for each model) into one and the same graph. I have a data set of category 1-5 Likert responses in 400 rows in sets of 8 columns...
View ArticleMy data seems to be structured in correctly when making a plot
I have posted about this graph before but I am getting the same issue and I think it may be due to my data set. This is what I am working off of: Date Surface Surface pH Temperature 1 2019-05-13 12.08...
View Articlefind JSON in string with recursion limit in r (windows)
I want to build a function that extracts jsons from strings in a generic way (for variable string Formats) with R on Windows.Thanks to #SO I am using:allJSONS <- gregexpr( pattern =...
View ArticleHow to get formatting of style in officer?
I want to write some documents with officer and I have some predefined styles in my word document that I load with read_docx(). Now I can look at the styles but I especially want to know which font...
View Articlemodularize Shiny app: CSV and Chart modules
I want to create a modularized Shiny app where one module, dataUpload, is used to import a CSV and another module, chart, is used to Create dynamic x and y dropdowns based on the column names within...
View ArticleHow can I compute the difference in consecutive rows for multiple columns?
I have a df consisting of daily returns for various maturities. The first column consists of dates and the next 12 are maturities. I want to create a new df that calculates the difference in...
View ArticleHow to combine 2 dataframes based on one column and have the other columns...
This question already has an answer here:How to join (merge) data frames (inner, outer, left, right) 13 answersI am trying to combine df1 and df2 based on ID, and have the other columns just fill in...
View ArticleR encoding problem while web scraping - how to fix broken text?
While web scraping, some of the text retrieved was broken, very similar with foreign text when the incorrect encoding is used. The problem is: the encoding seems to be correct: "UTF-8". Is there any...
View ArticleUsing the same factor mapping for multiple columns in R
I'm trying to figure out how to use the same factor "mapping" for more than one column.For example, here's a data set of imaginary tennis matches, in which one player was the favorite and the other...
View Articlergl fade with depth, depth perception
How can I show objects further away with a fade-out effect in rgl? Currently, given a 3D scatter plot, R's rgl package displays objects further away with a smaller size. However, I still find it...
View ArticlePredict() alternatives that can handle many independent variables. Used for...
I am trying to do predict future site traffic based on survey data (iv1, iv2, iv3, etc). The model is supposed to train on the previous data, and predict future site traffic using data already...
View Article