Questions tagged [r]
R is a free, open-source programming language & software environment for statistical computing, bioinformatics, visualization & general computing. Please use minimal reproducible examples others can run using copy & paste. Show desired output entirely. Use dput() for data & specify all non-base packages with library(). Don't embed pictures for data or code, use indented code blocks instead. For statistics questions, use https://stats.stackexchange.com.
508,308
questions
0
votes
0
answers
8
views
Match word and scores from two separate datasets in R
Not an easy question, but I will try to explain the problem. I have a list of word, Vocabulary, ordered by tf score. Below an example of a Vocabulary with few entries.
Say that I have a Document for ...
0
votes
0
answers
11
views
How do I get rid of the weird long floating point error numbers that are shown when I convert a vector to a name of a vector [duplicate]
This function shows the floating point error when displaying the vector as names of another vector but not when it is displayed "normally"
test <- rep(NA, times = length(seq(from = -0.5, ...
0
votes
1
answer
18
views
Find average temperature from a range of datetime for each day in dataframe
This is a subset of the dataframe I have:
structure(list(name = c("waldorf", "waldorf", "waldorf", "waldorf",
"waldorf", "waldorf", "...
0
votes
1
answer
11
views
Possible issues with text encoding in R/RStudio
I'm having a strange problem when I read a .csv file using read_csv. I'm afraid I don't think I can produce a reproducible example because the issue may involve my current R/RStudio session and how ...
0
votes
0
answers
8
views
Google Cloud Platform Maps API key: Best practice to use in R to avoid incurring large API costs?
I'm using google maps API and ggmap to create a simple map of NYC in an RMarkdown document, in R:
install.packages("ggmap")
ggmap::register_google(key = "<your-api-key>", ...
0
votes
0
answers
8
views
Why does my mutate(across()) function not work in lapply? [duplicate]
I have a simple function that works just fine on one data frame but doesn't do anything when I use it in lapply.
For example:
df1 <- data.frame(x = c(1:5), y = c(11:14, NA))
df2 <- data.frame(...
-4
votes
0
answers
23
views
Dplyr ( count for total number/treatment) [closed]
I have data frame with two columns the first column is the number of children under the age of five that receive a treatment and the second column classifies the type of the treatment. I would like to ...
0
votes
0
answers
25
views
How to extract from multiple zip files only the csv files whose name starts with a specific string of characters in r? [duplicate]
Let's consider a folder myfile containing more than a hundred zip files (z001.zip, z002.zip, z003.zip ...) each always including 4 distinct csv files whose names always start with these three letters ...
0
votes
0
answers
10
views
Increasing fontsize of numbers in forestplot in R
I am trying to prepare a forest plot for summarizing patient survival outcomes in multiple cohorts using the forestplot package in R. The plot comes out fine but I am struggling to increase the size ...
0
votes
0
answers
11
views
Problems running accuracy metrics on Validation_Set using fable package
I am unable to let the ACCURACY function point only to the Validation_set. The code perfectly works only in case the first argument of Accuracy is the whole dataset("data_tsibble") but in ...
-1
votes
1
answer
27
views
Produce table with data bars in base R or ggplot2
I am looking to make a table with horizontal bar graphs in each cell to display continuous numeric data with 2 categorical independent variables. It would look similar to the below (fictional data):
...
0
votes
0
answers
19
views
Getting "invalid 'type' (character) of argument" error with numeric values when I do apply.weekly(data$x, sum)
I have a time series object and I am creating a list of the variables at different timesteps.
when I do apply.weekly( , mean) it works fine, but when I want to sum the values over a week it gives me..
...
1
vote
4
answers
54
views
Find row in Matrix A which is closest two Matrix B
Lets say I have two matrices A and B given by
set.seed(123)
m1 = matrix(runif(10*5), nrow = 10, ncol = 5)
m2 = matrix(runif(10*5), nrow = 10, ncol = 5)
I want to find for each row in matrix A the row ...
0
votes
0
answers
22
views
Making a ggplot2 Sankey plot in R less crowded
If I have a dataframe in R (called connections_df), that shows the connections between the two endpoints (endpoint1 and endpoint2) with the corresponding chromosome (CHR):
endpoint1 ...
-1
votes
0
answers
35
views
Making lines not overlap
I am creating a DGE plot for 2 samples. I want the lines in the resulting plot to NOT BE STACKED on top of each other, bot to be next to each other (so that both are visible).
## Load packages
if (! ...
1
vote
2
answers
32
views
R function 'transform' ignoring argument 'check.names=FALSE'
I'm having issues with the function transform in R and the argument check.names.
For example:
df <- data.frame('A' = sample(1:10), 'B' = sample(1:10), 'C(%)' = NA, check.names = FALSE)
> names(...
0
votes
0
answers
42
views
Conditional variable for COMPLETE DATA [duplicate]
Attached data :
id = c (2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
vm = c("12", "13", "14", "15", "16", "17", "18" "19", &...
1
vote
2
answers
26
views
Change the absolute value of elements in a dataframe without changing their sign (+ / -)
I have a dataframe of cumulative changes, which I am trying to convert into (multiplicative) factor values.
If all values were positive, I could simply add 1: e.g. a 25% increase would be 0.25, adding ...
1
vote
1
answer
14
views
Pattern fill in highcharter bar chart
I would like to create a column or bar chart with pattern fill in an R shiny app. It seems to me that highcharts and related highcharter package should be able to do the job, but I could not find a ...
3
votes
1
answer
44
views
In R, how and where does the underlying C functions get their argument inputs?
I'm trying to understand what happens at the C level when I call a function in R. For instance, print("Hello, World!") will call UseMethod("print"). From the "table" in ...
-1
votes
0
answers
18
views
In ggHoriPlot, geom_horizon will create fill Categories. What the meanning?
In ggHoriPlot,geom_horizon will create fill Categories ypos3 .. yneg1 ..yneg13 ,refer to the legend in attached image.
How to understand Categories and it's created according what kind of logic ? ...
0
votes
0
answers
5
views
KFAS package: Why I can't pass SSMCustom state space object to SSModel formula?
I am trying to create SSModel from KFAS package in R. In the code I got from someone it was done this way:
model <- KFAS::SSModel(ts ~ -1 + SSMcustom(Z = Z_t,T = T_t, R = R_t, Q = Q_t, a1 = a1_t, ...
2
votes
1
answer
67
views
lme4 (glmer): Something buggy with treatment of factors in 4-way interactions
I have a dataset for which I am making a series of complex generalized linear mixed-effects models with the lme4 package in R. I have experience with glmer and this type of experimental data, but I'...
0
votes
1
answer
21
views
how can I force the scale in ggplot to be in the middle of the data range?
In the plot below, the range in a goes from 0.001 to 0.7 but the legend doesn't have the middle value in the cyan color. Is there a way I can force that the middle value in the range of a be in the ...
0
votes
0
answers
11
views
How to change the line-height only in the code chunk when using Rmd in Rstudio
I'm looking for a way to modify the .rstheme file and adjust the line-height in a R markdown document. Specifically I want the code chunk in the Rmd file to have a line-height of 1.2 and for the other ...
3
votes
0
answers
25
views
R parallel: Stopping a cluster you don't have the object for?
I am working with a function that starts with parallel::makeCluster() and ends with parallel::stopCluster(). Sometimes it crashes in the middle and does not stop the cluster.
Demonstration code:
...
0
votes
0
answers
27
views
How to remove real-time NA rows?
I'm writing a code in shiny to input data in real time and download a csv file, but I want to remove rows with NA in the final output file.
Is it difficult to remove rows in real time in shiny?
Is it ...
0
votes
0
answers
9
views
RStudio: Failure to install 'imager'
I am attempting to do the tutortial "Getting started with imager", but the very first instruction library(imager) generates a long error message, with only the first part shown below
Error: ...
1
vote
0
answers
25
views
Fix order of stacks but allow colour to change
The data and code for this question were adapted from:
How to fill colors of stacked bar plot depending on colors column of df in R using ggplot
I want to fix the order of country appearance in each ...
0
votes
0
answers
36
views
Exact same line of code not working between 2 PCs
On my home PC with R4.4.0
avg_demand_per_yearday <- aggregate(demand ~ yearday, df, 'mean')
it works as expexted. On my work machine with R4.4.1 an error occurs
Error in UseMethod("aggregate&...