Using mutate over multiples columns with a for loop to recode values
I need to recode values over multiple columns of a data frame based on another table.I have to recode the values of multiple columns of a data table using a side table. The values correspond to...
View Articler - Average timestamps excluding the day
I want to average two timestamps, but excluding the day. For example, I need the average of 9:00 AM of Monday and 10:00 AM of Tuesday to be just 9:30 AM. Take the following code as...
View ArticlePlace strip panels on opposite sides of plot
Some journals require that figures with several graphs have each of the plots lettered. I'm trying to do the same with facet_wrap in ggplot2 because I've organized the data in such a way that...
View ArticleHow to Read in xls file that requires permission to open in R
I have several xls files I need to read in and combine into one dataframe. I trydf <- readxl::read_excel("file.xls") ordf <- readxl::read_xls("file.xls") but neither works. I get the following...
View ArticleGrouping elements in legend fails with ggplotly
In the following example, grouping ggplot-elements appears to work, until I convert the plot with plotly::ggplotly(). I'm struggling to understand if this is because I'm doing something wrong, or if...
View ArticleSwitching values of a list with multiple conditions in R [duplicate]
This question already has an answer here:What's the differences between & and &&, | and || in R? [duplicate] 1 answerI'm new to R and I have a little problem with switching values of list...
View Article"Cannot take a sample larger than the population when 'replace = FALSE" [closed]
I have a problem which I could not solve through the already asked questions in this Forum. Further on in this Question you will find the Google Link to my Data-Set and the Code I wrote.Now to my...
View ArticleR Conditionally Merge Rows
I have a very large database (with thousands of questions) from a forum where people answer questions and their answers are accepted or not. If someone answers more than once I need to combine their...
View ArticlePackage ("qdap") fails to load with multiple errors
While installing qdap I have not faced any errors. But when loading the library, I face the follwing errors.> library(qdap) Loading required package: qdapDictionaries Loading required package:...
View ArticleIn R, how can loop multiple variable at the same?
I am wondering of how can I loop the multiple variables at the same time in R.For example,a = c(1, 2, 3) b = c(4, 5, 6) And then for loop, the below code didnt work.for (i, j in a, b) { print(i)...
View ArticleScraping pages with inconsistent lengths in dataframe
I want to scrape all the names from this page. With the result of one tibble of three columns. My code only works if all the data is there hence my error: Error: Tibble columns must have consistent...
View ArticleConditionally mutate multiple columns in R
I have a dataframe with a factor column with j levels, as well as j vectors of length k. I would like to populate k columns in the former dataframe with values from the latter vectors, conditional on...
View Articler- grepl to find multiple strings exists
grepl("instance|percentage", labelTest$Text) will return true if any one of instance or percentage is present.How will i get true only when both the terms are present.
View ArticleCreating new conditioned factor variable from multiple binary variables in R
I need to make a new 3-level categorical variable that reflects whether a subject died of a certain class of drug in an overdose. The levels would be something like: "Class A only", "Class B only",...
View Articleggplot specify longitude/latitude axis breaks
I am using the following code to create a map of one 'trial_area' from a shapefile and overlaying a coastline and 'prod_areas' from a second shapefile. I'm then using the coord_sf to zoom the map to...
View ArticleCreate a column grouping strings text extracted from a column based on...
this is my datasetid text 1 "red" 1 "blue" 2 "light blue" 2 "red" 2 "yellow" 3 "dark green"this is the result I want to obtain: id text2 1 "red, blue" 2 "light blue, red, yellow" 3 "dark...
View ArticlePredict function in R: factor has new levels error
So I've built a MLR model in R, it has a categorical variable in it with like 93 levels (so many). I tried grouping some levels or removing the predictor altogether but this had a negative impact so...
View ArticleCounting intersections per run of 1s in the first of two logical vectors
A more general version of this question has been answered here. A user proposed I ask this more specific version of the question as a separate post.I have two logical vectors which look like this:x =...
View Articleturning a character vector into a single row dataframe in R
I have a vector that I want to turn into a single row dataframe, this code works:vec <- c("a","b","c","d","e") df<- as.data.frame(t(as.data.frame(vec))) but is so clunky, does anyone have a more...
View ArticleR function for making rotated scatter plots
I am working on a Shiny app that produces some data visualizations. I was wondering if there was a way to rotate a scatter plot's axis 45 degrees. (i.e. the scatter plot would have a diamond shape when...
View Article