Pivot by group for unequal data size
I have the following DF:DF = structure(list(ID = c(21785L, 21785L, 21785L), V1 = c(0.828273303, 6.404590021, 0.775568448), V2 = c(2L, 3L, 2L), V3 = c(NA, 1.122899914, 0.850113234), V4 = c(NA, 4L, 3L),...
View Articledifference between working on R directly working under...
I was just reading the article https://spark.rstudio.com/ But I am not sure what is the difference between working on R directly working under install.packages("sparklyr") packagesCould you let me...
View ArticleText to be written must be a length-one character vector
After installing the new version of shiny (1.4.0) package, I face a strange error message > Warning: Error in writeImpl: Text to be written must be a length-one > character vector [No stack trace...
View ArticleOptimise R code (SQL read and write) for quicker performace
The below double nested loop runs across 850 branches, 2 service points and 25 specific needs. As it stands the total estimated run time is 70 hours. Please help me optimise so this runs quicker?Code...
View Articlereturn ID's of unique combinations
My data table has the following formatID Var1 Var2 Var3 ... 1_1 0 0 1 ... 1_2 1 1 0 ... 1_3 0 0 1 ... ... ... ... ... ... I want to extract the ID's from unique combinations (Varcolumns). Getting the...
View ArticleCounting the number of specific integers per column in an R matrix
I have a matrix (10 x 100) where I need to count the number of each integer per column so I have a final matrix that is (3 x 100). Counts for 0, 1, and 2 per column. I think the apply function will be...
View ArticleHow to calculate a particular index in R
Hello everyone, I need your help for the calculation of this expression. I have a dataframe with income streams (made of 5 "t" periods) from different years. What I need is a command to make R...
View Articlecor and cov2cor different results with use = pairwise.complete.obs
Running: cor(x, use = "pairwise.complete.obs")` vs runningc <- cov(x, use = "pairwise.complete.obs") cov2cor(c) give different results. Anyone know why and which one gives correct results? Both...
View ArticleError in if() missing value where TRUE/FALSE needed, but there's actually a...
I have this error in R. I'm working with a database, where my NA values are called "# VALOR N/A", so I did a simple function to see how many of this values I have. estavencido <- function(a){ count...
View Articleset missing values for multiple labelled variables
How to I set missing values for multiple labelled vectors in a data frame. I am working with a survey dataset from spss. I am dealing with about 20 different variables, with the same missing values. So...
View ArticleDynamic naming of download filename from DataTable buttons extension in R shiny
I have: library(shiny) library(DT) ui <- fluidPage( h2("Explorer"), tabPanel(h3("Inspector"), p("Overview of data for a particular sample."), selectInput(inputId = "sample", label = h3("Select...
View Articlegeom_dumbbell chart with scales for line and dots
I'm trying to make a dumbbell chart with additional information about change (green/red) and significance of the change (vol) and add an additional legend for the dots at the end of the dumbbells. My...
View Articleparse dates from multiple columns with NAs and dates hidden in text
I have a data.frame with dates distributed across columns and in a messy format: the year column contains years and NAs, the column date_old contains the format Month DD or DD (or a date duration) or...
View ArticleConvert frequency vector to logical matrix
I would like to convert a frequency vector (i.e. the colSums() of a matrix) to one of the possible versions of the original logical matrix in R. Something like: s <- c(1,2,3) # Some function of s #...
View ArticleCreating a vector of numbers based on letters
So, this is the question:"Create a function that given one word, return the position of word’s letters on letters vector. For example, if the word is ‘abba’, the function will return 1 2 2 1."What I...
View ArticleSuppress ggpairs messages when generating plot
ggpairs prints out a progress bar and estimated remaining time while generating plots, which is nice when used interactively since some of the computations can take a few seconds. But when making...
View Articlebeamer rmarkdown presentation unable to knit pdf file instead knit html...
I have a beamer rmarkdown file for preparing PDF presentation as teaching material. However, when I click knit with pdf, the output is displayed in html document, instead of beamer_presentation (pdf)....
View ArticleError in R Code if called in a function (multcompleters, strsplit:...
I would like to generate labels from a Tukey test inside a function. There it throws an error whereas if I call the code not inside a function it works absolutely fine.Other threads say the solution is...
View ArticlePopulating NAs and correcting data based on sequence within a sequence
I have a data frame with two issues that I am trying to correct. Here is a toy example. require(data.table) tempdt <-...
View Articlehow to properly plot igraph's graphs to make them comparable?
So, as in the title, I need to be able to plot some igraph's graphs and be able to compare them. To do so I believed that passing coordinates and then plotting them was enough. Then I found out that...
View Article