Category "r"

combine rows in data frame containing NA to make complete row

I know this is a duplicate Q but I can't seem to find the post again Using the following data df <- data.frame(A=c(1,1,2,2),B=c(NA,2,NA,4),C=c(3,NA,NA,5),D

Rstudio does not recognize MacTeX MacOSx 10.7.5, can't preview pdf

I have created an .md file, but to preview it in pdf format Rstudio requires MacTeX installation. I've installed it, read README file, everything is there, the

How to remove '.' from column names in a dataframe?

My dataframe which I read from a csv file has column names like this abc.def, ewf.asd.fkl, qqit.vsf.addw.coil I want to remove the '.' from all the names and

Xgboost tweedie: Why is the formula to get the prediction from the link = exp(link)/ 2?

When I run a Tweedie GLM, one can get the prediction from the link by doing exp(link). To get the prediction for a Tweedie GLM, I get the prediction from the li

How do you reorder categories on R using fct_recode()

I keep trying to reorder my variables using this function: ces2019 <- mutate(ces2019,vote_intention = fct_recode(vote_intention,"Certain Not to vote" = "(4)

R - Correlation heatmap created with ggplot2: How can I flip the labels on the y-axis?

I found this easy way to create a correlation heatmap using ggplot2: data(attitude) library(ggplot2) library(reshape2) ggplot(melt(cor(attitude)), aes(Var1,

How to install multiple packages?

How would I got about installing multiple packages in R? I tried the following code: install.packages("EIAdata", "gdata", "ggmap", "ggplot2","gridExtra","ISO

least square regression model

What is behind Approx and approxfun? I know that these two functions perform a linear interpolation, however I didn't find any reference on how they do that. I

List xlsx sheetnames with R

Is it possible to generate a list of sheetnames within an xlsx file? Or perhaps, can I check if a sheet name exists, and if not, proceed with some designated fu

Solving Intermediate Microeconomics Problems in R

Right now im trying to figure out how to solve standard constrained optimization problems in R which would usually be solved by hand with the use of a lagrangia

How to add Latex code in ggplot2 legend labels?

Consider the following example: p <- ggplot(data = data.frame(A=c(1,2,3,4,5,6,7,8),B=c(4,1,2,1,3,2,4,1),C=c("A","B","A","B","A","B","A","B"))) p <- p + g

Extracting coeftest results into a data frame

I'm trying to extract model coefficients from R into a data frame that I can then combine into one large dataset with some other model results from Stata. Using

Getting bounding box from leaflet in R

I am using R, RStudio and the leaflet package to visualise a map. I would like to get the the min and max lat-longs of of the bounding box of a leaflet object.

Barplot/barchart in R [duplicate]

I have a data table with two small columns. I want to do a pairwise comparison between the values. The first column is results of one test an

Save package settings between sessions

Is there a definitive way to save options or information pertaining to a certain package between sessions? For example say somebody made a game and released it

Importing multiple Excel files with multiple sheets and creating a new column based on sheet's names

I am trying to upload multiple Excels files (same format) and each of these files has multiple sheets, in nature each Excel file has information about a hotel b

Stacking multiple plots, vertically with the same x axis but different Y axes in R

I have a data.frame with multiple time series vectors against a date:time vector. I would like to plot all of the relevant vectors, vertically stacked on separa

targets::tar_map() example? (R targets static branching)

Does anyone have an example of how to use static branching from the targets package (R)? I'm reading targets manual on static branching but I'm having a hard ti

ggplot2: how to color a graph by multiple variables

I am fairly certain I have seen a solution for this somewhere, but as I have been unable to find it, here is my problem. I have some time series data identifi

Making a matrix from lsmeans contrasts return

To create the data frame: num <- sample(1:25, 20) x <- data.frame("Day_eclosion" = num, "Developmental" = c("AP", "MA", "JU", "L"), "Replicate" = 1:5)