Category "r"

Set a time varying variable to its initial value in a dataframe

I have this dataframe, which I have data for US's states population for different time periods, I want to set the population of every state to its initial value

Cosine similarity between rows of two large dataframes in R

I've two dataframes DF1 and DF2. One of them is a very large DF. I've created examples DF1 and 2 like this: library(tidyverse) A<-rep(c('Mavs', 'Spurs', 'La

Mean calculation between dataframes in list in R

I have a list of dataframes that all have the same format (same number of rows, same number of columns and columns have the same name). I would like to create a

How to read CSV file in R without losing data?

I'm importing CSV file to Rstudio. I use this command df <- read.csv("C:/Users/Ibad/Desktop/corona.csv") But I see there are many missing(NA) values in Rstu

reorder bar plot by fill in R

How to set this plot in ascending order? many thanks in advance. library(ggplot2) library(reshape2) iris2 <- melt(iris, id.vars="Species"); iris2 ggplot(da

How to add pooled standard error in tbl_summary() and eta effect size?

I am trying to include Pooled Standard Error (PSE) and Eta square to tbl_summary(). PSE is calculated by sqrt(mean(residuals^2)/n), I tried to calculate step by

Adding a summary table to facet grid box plot

I am trying to add a table that summarizes the info I have in a facet grid boxplot to the same plot. df<- structure(list(design = c("F", "F", "F", "F", "H",

What is this R call with current continuation code doing?

Here is a small chunk of R from Luke Tierney's codetools package: if (! exists("callCC")) callCC <- function(fun) { value <- NULL delayedAssign("t

Paste together results within case_when (if-else) statements

I want to paste together results within the same case_when statement (i.e., if multiple statements are true for a given row). I know that I could do something l

set.seed in for loop

I'm doing some analysis and I had to impute some values. To do so, I write this chunk of code: A) set.seed(1) for (i in 2:length (Dataset[-c(8,11)])) { D

Go from long to wide using tidyr's pivot_wider

I have a simple long df where every element in the fi column should be a new column in the wide df. So the new df should have 10 columns A:J. The wide df should

I can't install the sf package when I use the renv package in a project

I started a new project in Rstudio and selected the option to use renv. The first thing I did was type the command install.packages('sf') and R returned the mes

Tell `kwic()` to ignore stopwords when situating keywords in context?

I once again have a question about the kwic() function from the quanteda package. I want to extract the five words around a specific keyword (in the example bel

R: converting text with irregular length into dataframe

Simplified example of a text i have after importing with readlines: text <- c("just", "stuff", "nothing", "interesting", "date", "06.05.2022", "number", "1/

WGCNA functions not found

I'm applying WGCNA to RNASeq data following this tutorial. For several functions it give me an error that the package functions are not found. > sft <- pi

dopar% and %foreach% failed to work for gmapsdistance

I am currently trying to apply parallelization with the gmapsdistance package (driving mode = bicycling) to speed up the computation of the for loop that contai

Error when renaming multiple columns and using add_overall() in tbl_summary

I am trying to create summary tables. I want to split these by site and have a "Total" column. However, when I try to rename multiple columns AND use add_overal

Matching and indexing through two dataframes and one matrix

I have a dataframe events with xy-coords of unique points. I have a dataframe all_nodes with xy-coords of network nodes. All points of events are also in all_no

Sampling submatrices in R

Given a matrix like mat > set.seed(1) > mat <- matrix(rbinom(100,1,0.5),10,10) > rownames(mat) <- paste0(sample(LETTERS[1:2],10,replace=T),c(1:nr

Evaluate and save Argument variable value during function definition?

Consider this function plus_x: y <- 1 plus_x <- function(input, x = y){ return(input + x) } here the y default-value for x is evaluated during the fun