Drop rows which are duplicates regarding certain columns

I want to identify and remove observations which are duplicates in certain aspects. In my example, I want to get rid of rows 1 and 6, as they are the same in both V1 and V2. That they differ in V3 shouldn’t matter. df <- data.frame(V1 = c("a","b","c","a","c","a"), V2 = c(1,2,1,2,3,1), V3 = c(1,2,3,4,5,6)) Applying… Read More Drop rows which are duplicates regarding certain columns

Adding 5th and 95th Percentile to List in R

Is there a method to add in 5th and 95th percentile to the list below? mtcars %>% summarize(across(where(is.numeric), list(median = median), na.rm = TRUE)) I tried the below, but I think I am missing something. mtcars %>% summarize(across(where(is.numeric), list(mean = mean, q95=quantile(, .95), q5=quantile(, .05)), na.rm = TRUE)) Any help would be appreciated! Thanks! >Solution… Read More Adding 5th and 95th Percentile to List in R

Adding 5th and 95th Percentile to List in R

Is there a method to add in 5th and 95th percentile to the list below? mtcars %>% summarize(across(where(is.numeric), list(median = median), na.rm = TRUE)) I tried the below, but I think I am missing something. mtcars %>% summarize(across(where(is.numeric), list(mean = mean, q95=quantile(, .95), q5=quantile(, .05)), na.rm = TRUE)) Any help would be appreciated! Thanks! >Solution… Read More Adding 5th and 95th Percentile to List in R

Efficiently assigning multiple variables created from a subset of grouped data in R

I am trying to improve the efficiency of code that is already working. For instance, consider the toy dataset below: df = data.frame(id = c(1,1,2,2,2,3,3,3), date = c(12,13,1,4,5,9,10,12), visit = c("out","in","in","out","out","out","in","in")) df id date visit 1 12 out 1 13 in 2 1 in 2 4 out 2 5 out 3 9 out 3 10… Read More Efficiently assigning multiple variables created from a subset of grouped data in R

reate a column from another column based on keywords

Based on the data below how can I get add a third Type colummn? The type of hospital will be determined based on certain words in the hospital names. Word Type Government Government Govt Government St Jude Religious Catholic Religious District District Community Community Divine Mercy Religious St. Luke Religious St. Theresa Religious Islamic Religious… Read More reate a column from another column based on keywords