Category "r"

How can I reshape a long dataset into a short data set with multiple variables

**UPDATE My data set contains 314090 observations in the following format: UPDATEDID BRIEF_ID gamma LDR_SUM LDR_Topic LDR_7Code 16 04999120040277 2.879744e-03

can you use split_cols_by and also get a total column?

I'm making a table like this: basic_table() %>% split_cols_by("ARM") %>% analyze(vars = c("AGE", "BMRKR1"), afun = function(x) { in_rows( "M

R: How to remove spikes/outliers on ggplot2

Given the following R script: library(glue) library(ggplot2) library(tidyverse) library(magrittr) library(stringi) library(dplyr) ir.data <- read.csv(file="

RASTER TO VECTOR : WriteVector from terra package leads to fatal error

I have this sampled code that I tried on RStudio these last days : library ('terra') binar <- rast("C:/Users/BIC_/Desktop/21_binarisation_SWIR.tif") poly_ra

Convert date of birth to age

I want to convert date of birth to age using the following code df$age <- round(as.numeric(Sys.Date()-as.Date(df$DOB),format="%d/%m/%y")/365) The format of

R Count Frequency of Custom Dictionary in a Dataframe Column but Group them

I have a task, which is too complex for my R-knowledge. I have a dataframe with Tweets-data, including a column that consists of the usernames, data of the Twee

Problem when creating a weights column in the table

Running regression with panel data on different geographical levels in the US and Euro area with weights that essentially look like this: lm(log(POP25) ~ log(EM

Transform a list of dataframes to a nested dataframe

I'm struggling with this problem: I have three lists of dataframes (each list has the same number of rows, each dataframe has 3 columns). I want to combine the

Batch removing the second sheet from many excel sheets in R?

I have many excel sheets that I need to remove the second sheet before importing them. All files are .xlsx type in one folder and have same format. What kind of

I need to verify that a variable exists in a database. Shiny in R

I have a query that gives me a dataframe. When I receive the data frame, I use this code to make some numeric variables: variables_numeric<-c("A","B","C","D"

ggplot line legend disappears with alpha < 1

When trying to plot some data in ggplot2 using geom_line(), I noticed that the legend items become empty if I use alpha < 1. How can I fix this and why is th

Access an element of a list in the same manner how you access an element of a matrix

I have a matrix: mat <- matrix(c(3,9,5,1,-2,8), nrow = 2) [,1] [,2] [,3] [1,] 3 5 -2 [2,] 9 1 8 I have a list: lst <- as.list(dat

How to use as_hms in a for loop in R

I have multiple csv files with the columns "timestamp" and "users_holding" I was able to split the timestamp column into two columns "Date" and "Time". I am now

I can't run rshiny prefectly in vscode T_T

When I am runing shiny in vscode I can't draw a plot. Even the example shiny::runExample("01_hello") enter image description here this is my sessionInfo() R ve

Add stars to p-value

I have calculated the Anova F-Test p-value for differences in means for several variables. Now I would like to add "stars" that indicate the significance level

422 Error when using httr for uploading data to batchPrediction API (data robot)

Disclaimer: This error is related to a subscription-based tool and hence the issue is likely not going to be reproducible for any reader. Nevertheless, any sugg

Melt a frequency table in order to use ggplot2

I have a "frequency table" similar to this one # Create a matrix df<- matrix(sample(0:10,35,replace=T),nrow=5, ncol=7) # Rename columns and rows colnames

case_when fails when condition checks for rows that don't exist

Consider this data: df <- data.frame(group = c(1, 2, 2, 2), start = c(2, 7, 7, 7), stop = c(8, 7, 8, 9),

Counting pixels of same value in R

I need help with counting pixels of the same value in R. I'm doing a master thesis and part of it is calculating the NDWI of an area before and after floods so

How can I reorder facet wrap by the values of the first column?

The following code is from Stefan, who answered a related question library(ggplot2) library(dplyr) library(tidyr) library(tidytext) mtcars2 <- as_tibble(mtc