Category "r"

Return TRUE/FALSE if common elements/no common elements between vectors

I'm looking for an efficient way to create a boolean vector which returns TRUE if one or more of a number of specified variables e.g. c(1,2,3) are in another ve

Glue vector to string

I want to produce this string: All my variables: a, b, c from this variable vars <- c("a", "b", "c") using glue(). My best attempt so far is: library(glu

Placing Commas Between Names

I am trying to find out if certain patterns appear within a data frame. Suppose I have the following "dictionary of patterns" (notice "james" vs "jamesj"): patt

Is there any way to improve performance (e.g. vectorize) this look-up and recoding problem implemented by a for loop?

I need to make recodings to data sets of the following form. # List elements of varying length set.seed(12345) n = 1e3 m = sample(2:5, n, T) V = list() for(i

How do I group my date variable into month/year in R?

I have a "date" vector, that contains dates in mm/dd/yyyy format: head(Entered_Date,5) [1] 1/5/1998 1/5/1998 1/5/1998 1/5/1998 1/5/1998 I am trying to plot

Group-based trajectory modelling in R

I've been looking for a way to conduct group-based trajectory modeling in R with no avail. Something along the lines of what PROC TRAJ (http://www.andrew.cmu.e

Leaflet map 'Error in polygonData.default(data) : Don't know how to get path data from object of class data.frame'

I'm trying to create a leaflet map of census data. I have a csv file contains the number of deaths across Ireland. The data consists of the year($Year), the Sex

Encoding and raw in R

I not sure if this is a bug or not. If I encode one of the characters to UTF-8 before converting to raw and back again, then the characters are not the same. I

Splitting row into two rows

I'm recently working with data as year <- c('1990', '1990', '1994', '2000', '2012') n1 <- c(30, 70, 20, 31, 10) n2 <- c(40, 60, 20, 21, 8) r1 <- c(0

Using R code to scrape data from a webpage into an Excel file

I have written a code in R which is supposed to retrieve certain information from a website and import it into an Excel file. I have used it for one website and

data.table join with date

hello im trying to extract some id with a group and Date in range > d1 id group Date 1: 1 A 2017-07-02 2: 2 A 2017-07-04 3: 3 A

Can I bound an st_distance call by a polygon?

I have seen similar posts on this topic (see, for example, here and here) but not one that is specific to the sf-tidyverse ecosystem. I have a series of lakes,

How can I merge an empty data frame and a data frame in R

I'm trying to merge to data frames like this: data1 <- data.frame(hola = as.numeric(), toma = as.character()) data2 <- data.frame(hola = as.numeric(1), t

R - Plots without Shiny - Create with JavaScript and produce screenshot

I have a Shiny application that generates one image after clicking an action button, and saves the screenshot of that image after pressing on another action but

append values in for loop R as in python

I am trying to reproduce the following functions created in Python in R. # Python def square_area(side): return side * side results = [] for i in range(1

How to permanently set fix my working dir?

Every time I restart R I issue the following command: setwd("C:/Users/avtarsingh/Downloads") How do make this my permanent working dir

Do not wipe out (user entered) values of reactive variables when changing input values

I want to collect individual information (name and age) as user input with the attached demo code. The initial number of individuals is 1, and when the user inc

R: Plotting panel model predictions using plm & pglm

I've created two regression models using a linear panel model with plm, and a generalized panel model using poisson with the pglm package. library(plm); librar

How to write raster to depreciated crs with terra?

I'm working with data that comes in a depreciated crs and want to avoid reprojection after converting the dataset to a SpatRaster. It seems that gdal is automat

Grouping items in certain intervals and multiplying them with their associated values under another column in R

df_final %>% mutate(Temp_Zones = cut(max_temp, c(0, 40, 60, 80, 100, 120))) %>% group_by(Temp_Zones) %>% summarize(X=n()) %>% save(df_f