# LaVOZs

The World’s Largest Online Community for Developers

'; Newest 'r' Questions - LavOzs.Com

# 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.

• ### create correct legend for geom_point with different colors and shapes; data comes from two variables with different levels

I already googled a lot on this problem, but none of the suggested solutions worked: The plot shows actual and expected values for each subject on four sessions ('sitz' 1 to 4). The actual value and ...
• ### How to draw color index in the right side of the heat map graph in R?, something like within a red circle in the attached pic

Summarize the problem How to dow color index in the right side of the graph, something like within a red circle in the attached pic Describe what you’ve tried enter image description here Used code: ...
• ### Partioning points into equal groups from their average

I have a set of points such as this, and I am trying to group or cluster them into four groups of equal size based on their distance to their mean. df <- data.frame(x = rnorm(50, 0, 1), ...
• ### Create new count variable conditional on previous values within group

I have a dataframe with group and time-id. Now I want to create a new count variable, called X2, conditional on previous values of X1 within each group. Suppose I have the following dataframe, ...
• ### Error in FUN(X[[i]], …) : object 'a' not found

I am trying to plot relationship between two variables- represented by points regression line. I also want to add two grey panels on this plot as shown in the graphics below. I wrote the code couple ...
• ### Speed up loop of iteratively computing values depending on previous row and excluding rows not meeting criteria in R

I am fairly new to R and I am currently having trouble with carrying out a loop in R. As far as I am concerned, slow loops in R are due to 'poor programming'. This is most likely also the case here (...
• ### Remove phone country code using Regex in R

I am trying to clean up a column of phone numbers in a df. I would like to remove the country code (254) from the start of the phone number. Occasionally there are repeats of this country code (...
• ### grid.arrange with non consecutive listed plots [closed]

I have about 79 plots in a list and I'm trying to use grid.arrange to get a nice overview. I wanted to use facet_wrap but at this point grid.arrange seems more easier. Most of the plots are in ...
• ### Problem with file size using fread (to load) and write.csv. From 20GB to > 60GB in writing phase

My problem is that write.csv - or something else in my work process - has increment my file size from 19GB to more than 60GB. I mean more than 60GB because the saving process was interrupted because ...
• ### Match columns with several conditions efficiently

I have a big dataframe in which I have two columns containing dates. For each individual (id), date.x contains a unique date but date.y contains several dates. I would like to match the dates ...
• ### Add legend to ordirgl {vegan3d}

I am trying to add a legend to a graphic produced using ordirgl() from the vegan3d package. I have been successful in doing this using plot3d() and legend3d() in the rgl package. I prefer some of the ...
• ### httr: Error in curl::curl_fetch_memory(url, handle = handle) : Failure when receiving data from the peer - FileSize?

I am httr:POST(ing) a login form to get into the website. To receive the data I am using the httr::GET: GET("mock-url", user_agent("Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:...
• ### Is PCA possible in 2x2 matrix taken from 3x3 population covariance matrix

Population matrix is given as below: $\sum$= \begin{bmatrix} 1 & k & 0\ k & 1 & k\ 0 & k & 1\end{bmatrix} May I know if I want only first two Principal Components, PC1 and PC2,...
• ### Gather same years in a dataframe in r?

There are two years (2011 and 2012) information in my data. I want to gather same years as shown in the output part. And I want the output as dataframe as shown below. Here is my sample data which ...
• ### R: Adding columns / manipulating a data frame

I am trying to categorize a data set by grouping the Months column(with variables 1-12) into four groups. Winter(1-3), Spring (4-6), Summer(7-9) and Fall(10-12). I want to add in a NEW column, that ...
• ### Subsetting five or more columns with different conditions R data.table

I have a data.table that looks like this: COUNTRY GENDER CURRENCY INCOME_GROUP YEAR FRANCE MAN EURO HIGH 2014 GERMANY WOMEN EURO LOW ...
• ### R non-conformable arguments error when using rootSolve's uniroot.all

In R, I have written a function rootfn_dimRet1 which I then pass to uniroot.all() from the rootSolve package. My function rootfn_dimRet1 works fine when run by itself. However, when I then pass it to ...
• ### Is it possible to add an element to the RStudio's UI using addins?

I always considered how it's a bit inconvenient that RStudio doesn't offer a Variable View akin to the one found in SPSS. Basically all that would be required for the beginning is to make a table like ...
• ### Give group ID for date periods

i'm trying to automatize the attribution of a group number by periods of time. Because i'm writing of function to aggregate time series of weather data by different time periods defined by the user. ...
• ### What can I do to fix my R code using b-spline function?

Here is my data: +-----+-------------+ | age | wage | +-----+-------------+ | 18 | 75.04315402 | | 24 | 70.47601965 | | 45 | 130.9821774 | | 43 | 154.685293 | | 50 | 75.04315402 | | 54 | ...
• ### Adding an interactive time slider to leaflet map in R

I am trying to create an interactive, color coded map of the US using leaflet. My goal is to have the fill for each state change when the time slider is moved. I've got the map and the time slider ...
• ### Recode variable in multiples columns based on condition using function inside mutate_all

I've this data : # A tibble: 169 x 5 Topical Anesthesist Skin Glue Sedation Servi~ Child Life Ther~ Hypnosis <chr> ...

• ### How to generate similarity scores heatmap from multiple gene lists in R

Problem I have a melted dataframe of 19 different tumor types, each with associated marker genes. I want to visualize the similarity between tumor types to see how they cluster. I have a plan to ...
• ### Long facet_wrap labels in ggplotly / plotly overlap facet's strip.background

I've got a plot like the one below, where I need to display a plot title and some long facet labels. In ggplot2, it looks just fine. Reprex: library(ggplot2) library(stringr) library(plotly) iris\$...
• ### Tools to debug through R Code on Unix Server

I have my R code on Unix Server and as there is no UI I am not able to debug my code through RStudio. Do we have any tools for R to debug through the code?
• ### Reshaping multiple columns in R

I have this following data: df <- data.frame( wave = c(350, 352), cdom = c(0.164910664183534, 0.161336423973549), total = c(0.173292853508359, 0.164541380243188), wave_1 = c(350, 352), ...
• ### Layering two different types of plots into one using faceting and ggplot2

Data Code that I wrote for the plot: ggplot(summary_df_cont, aes(x=continent, y=total_cases, fill=type)) + geom_bar(stat = "identity") + facet_wrap(~type) gives me MY QUESTION: 1. Is there anyway ...
• ### Explanation of tilde in function arguments

I try to understang how to plot cumulative lines animation with plotly. The code from "Plotly R Open Source Graphing Library" is below: library(plotly) accumulate_by <- function(dat, var) { var ...
• ### When using “apply”, can I return just one value of a function?

I'm not familiarized with the apply in R. When I try to return just one value of the function, it can't return that. This problem might be very easy to solve, but I'm not getting to it. For example, ...
• ### friedmanTestBMR using one classifier with multitasks - mlr

I have run a benchmark experiment with several tasks, containing different subsets of the data, with one classifier (random forest from the package ranger). Now I would like to compare on significance ...
• ### Overlay plot on map background in R

I want to make a windrose plot on a specific location. Windrose can be plot with openair package library(openair) windRose(mydata, "ws", "wd") or with ggplot using this function. What I am looking ...
• ### dplyr - how to recode to NA?

I'm trying the following: data %>% mutate_at(vars(Q1), recode, "I don't agree" = 0, "I agree" = 1, "I don't know" = NA) But I'm getting the following error: Q1 must be a double vector, not a ...
• ### Missing CPU time in nmf() function in R

I am running NMF on as below, it does not matter whether to include only this method or multiple methods: nfactors <- 2 nmf_multi <- nmf(V, nfactors, method=list("snmf/l"), seed="nndsvd", ....
• ### aws sagemaker: install new r packages error

I'm trying to use jupyter notebook in AWS sagemaker with an r kernel. However there is a specific library that I want to use (imager) that does not exist. Based on previous SO answers, I tried to do ...
• ### Matrix Optimization on R

I have 3 matrices, an A(7*7), B(30*7) matrix and a target matrix(30*7) the target matrix is given. I have a matrix A (7*7) which allows me to build a matrix B (30*7) in the following way: 1/ I take ...
• ### Set borders for words to convert to new string by specific character or word count exceeding specific length?

So I scraped this string from google "Raveena Tandon (born 26 October 1974) is an Indian actress who works in Hindi films." Basically I want to confirm that the first couple words in the search ...
• ### Self-made queue priority policy for Simulation with Simmer in R

I want to simulate a planning process in R. I found out that I have to use the simmer package for simulation in R. When the tasks arrive in my simulation, they all arrive on the 'Waiting List'. The ...
• ### How to ignore elements by data type in a list in r?

I have a sample data like below; Desired data type is double, but there are other types like list. How can I remove or ignore them? sample<-list(x1 = structure(c(0.266, 0.532, 0.797, 1....
• ### How to transform inconsistent yearly data to quinquennial averages?

I'm new to R and is trying to transform my yearly inconsisent dataset (data set does not necessarily contain data for every year, but do for some variables) into quinquennial averages. I'm trying to ...