New answers tagged r
Advice
0 votes
0 replies
0 views
Plotting words with different colors indicating different groups in R
yes I would want to reproduce this kind of graph in R. Apologies for not making this clearer in my question. In this case, I would prefer to plot letters with scores in Group1 only colored in red (the ...
Advice
0 votes
0 replies
0 views
Plotting words with different colors indicating different groups in R
Whats the goal here? Do you want to reproduce this kind of graph? Or highlight some points where x and y differ (by how much?) On the exemple graph, the color scale seems to be based on a calculated ...
0 votes
how to download files from a sharepoint folder with R
Here is another approach that can be considered : #' @export `%||%` <- function(x, y) { if (is.null(x) || length(x) == 0) y else x } #' @export encode_graph_path <- function(path) { path &...
Tooling
0 votes
0 replies
0 views
How to map a spatial object from WGS84 to another projection without deforming the map?
Thanks for the reply! What I really wonder is why is my map "cropped"? I'm supposed to have my raster from 20°S to 60°S, and yet it's limited to 30°S westside of the map. Is it the result of ...
0 votes
How to use a non-ASCII symbol (e.g. £) in an R package function?
Combining the two methods described in the other solutions (\uxxxx and intToUtf8()) is sometimes necessary or useful with regex, as shown below: I had this grepl() code: last_char <- "l" ;...
2 votes
Customising scale bar colours in rayshader to match map palette
Skip creating the legend using render_scalebar(). Instead, we can save the snapshot to a file, create the legend using {ggplot2} and then overlay it on top of the final image; render_snapshot("...
1 vote
Using group_by with user defined function
You can bypass the whole manual calculation with the package "qol" like this: library(qol) example <- tibble(Student.ID = c("#001","#002","#003","#004&...
Tooling
0 votes
0 replies
0 views
How to map a spatial object from WGS84 to another projection without deforming the map?
Changing from one projection to another will by definition change some combination of areas/form/distances/directions: https://www.axismaps.com/guide/map-projections I think it's the case that equal ...
-1 votes
Using group_by with user defined function
Here is another solution. First count the positives in Student.Attended == "Yes". Then, filter those and compute the percentage of entryby19 == "Yes". Finally, join the two results ...
1 vote
Using group_by with user defined function
I'm not quite sure I understand if this is the logic you want -- it's showing the number of distinct student IDs by Type (regardless of Attended), and the share of the Attended who had entryby19. ...
3 votes
Accepted
facetting a stratified KM curve in ggsurvfit
As Limey's answer shows, this is to do with the data format used by Survfit. One approach to getting a facet like plot is to create separate plots for each surg and put them together using patchwork. ...
3 votes
facetting a stratified KM curve in ggsurvfit
It seems the issue here is not the facetting, but rather the output data produced by survfit2. Consider survfit2(Surv(time, status) ~ sex + surg, data = df_colon) %>% broom::tidy() (Note that I've ...
2 votes
Using group_by with user defined function
I don't know exactly what your expected result is, but perhaps this will help you. As I suggest in my first comment, dplyr's group_xxxx family of functions may well be the way to go. In this case, ...
4 votes
Accepted
Facet label spacing and annotation positioning in forest plot
It's a bit hacky, but you could insert spaces using <span></span> = " " <span style='color:transparent;'>xxxxxxxx</span> = " " (8 spaces) and after ...
Tooling
1 vote
0 replies
0 views
How to map a spatial object from WGS84 to another projection without deforming the map?
You can't all projections introduce a distortion in area or shape.
3 votes
Build a shell command that returns its output
I do not have svn installed, but the R equivalent for Python's % is sprintf(); use it in system(): > filename <- 'a.txt' > ret <- system(sprintf('file %s', filename), intern=TRUE) > ret ...
0 votes
Simple BERT implementation on R side
I implemented the BERT model in R using the R package torch without dependence on Python. The code is available here : https://github.com/ManuHamel/rbert. Here is an example of how the package can be ...
2 votes
UpSetR - How to improve number rotation and change color?
You could patch UpSetR to do this, since this issue was not solved since 2017. library(UpSetR) X <- data.frame( name = 1:100000, food = rep(1, 100000), drink = c(rep(1, 50000), (rep(0, 50000)...
2 votes
UpSetR - How to improve number rotation and change color?
We can modify the grobs manually, after creating the plot. library(UpSetR) p <- upset(df, sets = c('food', 'drink', 'house'), main.bar.color = "blue", show.numbers =...
Best practices
2 votes
0 replies
0 views
Standardising predictors before using poly() in a GLMM
This is really a data modeling question, not a specific programming question. You should be asking at https://stats.stackexchange.com/ instead.
0 votes
Advice
2 votes
0 replies
0 views
How to use mathematical expression and italics in ggplot axis labels?
and it has been answered several times on SO.
Advice
0 votes
0 replies
0 views
R - Sort individual rows of a data.table by ascending order of the value in each column
To follow up on my original comment and to answer your question above, here is a tidyverse solution using the pivoting algorithm I described earlier. Note that I use d rather than data to avoid ...
0 votes
Find row with longest string in R
Here is a dplyr option: library(dplyr) DF %>% filter(nchar(V1) == max(nchar(V1)))
Advice
2 votes
0 replies
0 views
How to use mathematical expression and italics in ggplot axis labels?
This is more of a "how can I do it?" question than of an advice one, but here it goes. Instead of changing the data, create a labels vector with the plotmath expressions and add ...
3 votes
Accepted
ggplot2: element_textbox_simple causing line break text for no reason
Here's a minimal reproducible example. Since the operative thing here is the text wrapping in the legend title, I expect we can use simpler code and just keep that part. I expect it will work the same ...
Advice
0 votes
0 replies
0 views
R - Sort individual rows of a data.table by ascending order of the value in each column
@jared_mamrot, yes, that works perfectly! Thank you so much! See below: data <- structure(list(V1 = c(20, 2, 7, 20, 48, 12), V2 = c(1, 48, 23, 56, 28, 11), V3 = c(54, 20, 4, 51, 55, 30), V4 = c(...
Advice
0 votes
0 replies
0 views
R - Sort individual rows of a data.table by ascending order of the value in each column
Based off of @Limey's answer, I have written 2 sets of code, but neither one provides the satisfactory end result. Set 1 data <- structure(list(V1 = c(20, 2, 7, 20, 48, 12), V2 = c(1, 48, 23, 56, ...
Advice
3 votes
0 replies
0 views
R - Sort individual rows of a data.table by ascending order of the value in each column
Something like as.data.table(t(apply(t(data), 2, sort))) seems more straightforward; does that work with your actual data Irucka?
0 votes
how to do the mean absolute error (mae) on two dataframes with NaN in r
The error you are making is in how you are naming the 1st and 2nd arguments, df$AU and df2$UF1. The dollar sign has a special meaning in R, it's an extractor operator. The right way is mae1 <- ...
Advice
0 votes
0 replies
0 views
R - Sort individual rows of a data.table by ascending order of the value in each column
@Limey, thank you for the suggestion. I'll try that method as well.
Advice
0 votes
0 replies
0 views
R - Sort individual rows of a data.table by ascending order of the value in each column
After I posted the question, I came up with the following solution: data <- structure(list(V1 = c(20, 2, 7, 20, 48, 12), V2 = c(1, 48, 23, 56, 28, 11), V3 = c(54, 20, 4, 51, 55, 30), V4 = c(5, 28, ...
Advice
2 votes
0 replies
0 views
R - Sort individual rows of a data.table by ascending order of the value in each column
Pivot into long format Sort Recalculate the ID column Pivot into wide format This will work regardless of the number of rows and number of columns
0 votes
Using parallel computing to fit multiple models
For the parallel version, foreach + doParallel is the most straightforward drop-in: library(foreach) library(doParallel) cl <- makeCluster(parallel::detectCores() - 1) registerDoParallel(cl) ...
0 votes
Efficient Named Entity Recognition in R
Here is another approach that can be considered. I created a R package rcamembert which is an R based implementation of the Camembert model available on Hugging face using the R package torch. There ...
0 votes
I'm currently attempting to use the MEXC api to check SPOT account info. Is there a reason I keep getting error code 400?
Use the following pre-script with only recvWindow in the params for the v3 endpoint: const CryptoJS = require('crypto-js'); const timestamp = pm.environment.get("timestamp") const secret = ...
0 votes
Converting a scanned pdf to a searchable pdf in R
I created a new Rcpp binding for tesseract. The code is available here with the installaction code : https://github.com/ManuHamel/rtesseract. You can use this code to convert a scanned pdf to a ...
0 votes
Efficient Named Entity Recognition in R
Here is another approach that can be considered for entites recognition. You can consider using the R package rmitie which is a Rcpp binding to the mitie library. library(rmitie) > paths <- ...
0 votes
In R, how to do named entity recognition?
I created a R binding to the mitie library. The code is here available here : https://github.com/ManuHamel/rmitie. Here is an example of how you can use the library to perform entities recognition : ...
6 votes
How to mutate new variable according the formula string
Construct the entire mutate as a string and parse and evaluate it. Note that this still works even if the formula has commas in it because it does not muck with them. For example, consider the ...
5 votes
How to mutate new variable according the formula string
within(diamonds, eval(str2expression(sub(",", ";", my_formula2)))) # A tibble: 53,940 × 12 carat cut color clarity depth table price x y z total2 total <...
1 vote
Accepted
Roxygen2: how to remove newlines between usage statements?
I've found solution that is static rather than dynamic. It will render the documentation exactly as you wish. But whenever you update the function signatures, you must remember to also update the @...
1 vote
Installing C libraries in R?
I created a new Rcpp binding to libpostal : https://github.com/ManuHamel/rlibpostal. There is a code to install libpostal using R which is presented below : run_cmd <- function(cmd, args = ...
1 vote
there are two case_when() in code,the conditions are the same. Is the any way to simplify it
If you are open to another package you can do it like this with 'qol': library(qol) diamonds |> if.(color %in% c('E','I'), kpi_a = "A", kpi_b = 1.1) |> else_if.(color %in% c('J'...
0 votes
Store Tesseract Output in PDF using R
I created a new Rcpp binding for tesseract. The code is available here with the installaction code : https://github.com/ManuHamel/rtesseract. You can use this code to convert a scanned pdf to a ...
0 votes
Convert and save distance matrix to a specific format
This is a very old question, but I came across it while researching a similar problem, and wanted to add an answer with some more details that might be helpful to anyone else who Googles across this. ...
0 votes
Update Sharepoint metadata using R
I have been able to update a Sharepoint list with the following code : library(AzureGraph) library(jsonlite) `%||%` <- function(x, y) { if (is.null(x) || length(x) == 0) y else x } safe_name <...
0 votes
How to extract the metadata of a files in a SharePoint list using R?
Here is another approach that can be used : library(AzureGraph) library(jsonlite) `%||%` <- function(x, y) { if (is.null(x) || length(x) == 0) y else x } safe_name <- function(x) { x <- ...
0 votes
there are two case_when() in code,the conditions are the same. Is the any way to simplify it
Wrap a join solution up in a utility function Generalise for the case where NA is a kpi value to be assigned (so we can't rely on is.na or dplyr::coalesce for the default) Retain memory efficiency ...
3 votes
Accepted
How to mutate new variable according the formula string
It’s a bit more nuanced than that. In both cases, your input is being interpreted by mutate() as a single, unnamed argument. In the first example, this still works because mutate() falls back to its ...
Top 50 recent answers are included
Related Tags
r × 510704ggplot2 × 56919
dplyr × 37265
dataframe × 37049
shiny × 27859
plot × 15996
data.table × 13846
tidyverse × 10146
loops × 9676
function × 9259
for-loop × 9010
r-markdown × 8758
matrix × 8751
list × 8364
regex × 7443
rstudio × 6367
time-series × 6236
statistics × 6177
python × 5921
string × 5886
date × 5790
subset × 5235
plotly × 4903
knitr × 4786
regression × 4716