Questions tagged [r]

R is a free, open-source programming language & software environment for statistical computing, bioinformatics, visualization & general computing. Please use minimal reproducible example(s) others can run using copy & paste. Show desired output. 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.

Filter by
Sorted by
Tagged with
-1 votes
2 answers
40 views

How Do I Sum or Count a Factor Variable in R (for use in stacked bar chart)?

I want to create a stacked bar chart in R such that it shows the sum of levels of a feature over time. The feature is of type factor, "char", with levels A, B, H, N, P, U, W. Date feature is ...
0 votes
0 answers
4 views

Code chunks (sourced from external) work well when they are run in R Markdown, but fail when Knitting to Word

I have a rmd file which contains several code chunks. Each code chunk sources an external R script to generate a table (flextable). They work well (generate proper outputs) when I run the code chunks ...
0 votes
1 answer
12 views

R markdown: reduce space between text and image

In R markdown (output: html document), I want to insert an image between paragraphs (no text wrap). But when rendering I'm getting too large space between the paragraph and the image. I'm using the ...
0 votes
0 answers
13 views

Mapping values based on a dictionary in R

I'm looking for an algorithm to map the values in each column based on a chosen dictionary. Here's an example: Artificial data: df = data.frame( sex = c(0,0,0,1,0,1,0,1,1,1,0), icu = c(1,1,0,1,0,1,...
0 votes
1 answer
15 views

How to extract odds ratio values and put it in new table in r?

I calculated odds ratios using these lines of code: exp(cbind(OR = coef(table1), confint(table1))) exp(cbind(OR = coef(table2), confint(table2))) exp(cbind(OR = coef(table3), confint(table3))) exp(...
0 votes
0 answers
12 views

Trying to subset a large table using counts of all row values in a single column

Working in R on genomic data. I'm trying to subset a very large melted phyloseq table, which includes a column of phylum IDs, in order to remove rows containing phyla that occur less than 100000 times ...
0 votes
2 answers
532 views

Creating a null model in clogit in R

Every time I try to create a null model for my conditional logistic regression, R crashes. Here is a post by Matt O'Brian who also had this problem but did not ever note how it was fixed: How to ...
0 votes
0 answers
17 views

How do I pass a column name to a function involving mutate?

I am trying to write a function that takes a string and uses it as a column name in dplyr::mutate() on both sides of the equals sign. Here is an example of what I'd like to automate: cars %>% ...
0 votes
2 answers
30 views

Duplicate a data table while changing one column's value for each unique value in list

I have a data.table in R that I need to duplicate x amount of times with x being number of values in a list. The values in the list represent a column value I need to change/update for each unique ...
0 votes
0 answers
7 views

An error occurred when I was using the 'gof' in the 'ergm' package in r

After I set up an ergm named m03, I continued to use the command gof to fit the model, but there were the following errors, and I don't know what the reason is. If the data of this model is divided ...
0 votes
1 answer
49 views

Efficiently create many polygons

I want to create polygons inside an apply and want to do this as quickly as possible from a matrix of coordinates. I have some code and realized this is one of the slowest parts of my code. How can I ...
0 votes
1 answer
24 views

Filtering using If Function in R Shiny

I wanted to add a two-layer filter using the if function, because I find that I wasn't able to do much of the table manipulations (i.e. adding an additional aggregation row to have the calculation ...
0 votes
0 answers
18 views

How to change values in one dataframe using interpolated values from another dataframe in R

I have a dataframe J and I am currently using a code where I am performing some simple operations on this dataframe. The current code is at the end. What I want to get There is another dataframe named ...
1 vote
3 answers
63 views

Conditionally "mutate" a column (whether or not add a column)

Just as the title says, I'm trying to conditionally add a mutate step to my dplyr pipe. But I'm getting errors. Is there a tidy solution? Here's a simple example... max.mpg <- 50 mtcars %>% {...
0 votes
1 answer
22 views

Opening and reshaping xlsx files with nameless columns in r using a pattern

I'm working with French electoral data but I'm having issues opening xlsx files to work on them in r. I was wondering if anyone had had the same problem and found a solution. The issue is that only ...

15 30 50 per page
1
2 3 4 5
30604