Category "r"

Finding the elbow/knee in a curve

I have these data: x <- c(6.626,6.6234,6.6206,6.6008,6.5568,6.4953,6.4441,6.2186,6.0942,5.8833,5.702,5.4361,5.0501,4.744,4.1598,3.9318,3.4479,3.3462,3.108,2

Passing JSON into R function

I am trying to pass the following JSON into a function in R. The raw JSON { "type": "Polygon", "coordinates": [ [ [-122.68,42.77], [-1

dplyr::select function clashes with MASS::select

If I load the MASS package: library(MASS) then load try to run dplyr::select, I get a error: library(dplyr) mtcars %.% select(mpg) # Error in select(`__pre

Writing ISO8859 data to MySQL in R (error:"could not run statement: Invalid utf8 character string")

I need to import an SAS Transfer File (.xpt) to MySQL. Because I don't own SAS, I tried a) first importing the .xpt in R b) then using dbWriteTable from the li

Calling user defined functions from dplyr::mutate

I'm working on a project that involves many different tibbles, all of which have a period variable of the format YYYYMM. Below is an example of how all my tibbl

Calling user defined functions from dplyr::mutate

I'm working on a project that involves many different tibbles, all of which have a period variable of the format YYYYMM. Below is an example of how all my tibbl

Format number as fixed width, with leading zeros [duplicate]

The following code a <- seq(1,101,25) b <- paste("name", 1:length(a), sep = "_") produces this output: "name_1" "name_26" "name_51

R- How to set y-axis individually when using `facet_grid_sc()`

I want to plot the trend of the density (Density.est) of 3 species (Emar,Ecos and Sphyr) over time (2008,2009,2010) for two protection levels of a protected are

First day of the month from a POSIXct date time using lubridate

Given a POSIXct date time, how do you extract the first day of the month for aggregation? library(lubridate) full.date <- ymd_hms("2013-01-01 00:00:21")

Heatmaps of RNA SEQ data

This is my first time in working with RNA SEQ data and I have some problems with heatmap My data is as follows Data I wanted to create a heatmap to show tissu

Heatmaps of RNA SEQ data

This is my first time in working with RNA SEQ data and I have some problems with heatmap My data is as follows Data I wanted to create a heatmap to show tissu

Pandoc cannot find image path referenced in external HTML file pulled into R Markdown, despite using here() package

I am producing an HTML document through R Markdown, which uses a few external HTML documents for headers and footers. I am also using the here() package to allo

Using column numbers not names in lm()

Instead of something like lm(bp~height+age, data=mydata) I would like to specify the columns by number, not name. I tried lm(mydata[[1]]~mydata[[2]]+mydata[[3]

Saving an R-Script results in empty file

I have recently started using R for uni. I want to save my code using either save as or ctrl+s. However, the saved file is empty more often than not. For some r

Is there any Package for adding Arrows to lines in leaflet map

I am working on an interactive map in Leaflet thorough R studio, I want to show the direction of the roads with Arrows. I would be grateful if anyone helps me w

Error in if/while (condition) {: missing Value where TRUE/FALSE needed

I received this error message: Error in if (condition) { : missing value where TRUE/FALSE needed or Error in while (condition) { : missing value where TRUE/

How can I check if a matrix is an element of a list of matrices? in R

I'm pretty new to programming in R. I have a matrix of numbers mat, as well as a list of matrices matlist. I want to check if the matrix mat matches with (i.e

fs::dir_ls() returns unreadable output for file paths with chinese characters inside

I'm using fs::dir_ls() to get excel file paths under a directory main_path, but since there are Chinese characters in the file paths, I get an unreadable output

Is there a predict function for plm in R?

I have a small N large T panel which I am estimating via plm::plm (panel linear regression model), with fixed effects. Is there any way to get predicted values

tidyr use separate_rows over multiple columns

I have a data.frame where some cells contain strings of comma separate values: d <- data.frame(a=c(1:3), b=c("name1, name2, name3", "name4", "name5