gsub returning more than regex match

I have strings like so x = c( "blahblah, blah blah, Plate 3, blah blah" , "blah blah, blah_Plate 2_blah, blah" , "blah, blah, blah blah, blah plate_3" , "blah blah, blah, plate 5.txt" ) I want to get the plate number from all of these file names, ...
more »

2017-08-16 20:08 (2) Answers

How to prevent R from rounding seconds

I have a csv file containing timed data... now when i read it using read.csv.raw() it reads the time col as character---> "19:56:05.938836" "19:56:06.269024" "19:56:06.868525" "19:56:15.080690" "19:56:15.422007" "19:56:16.132036" now to convert it...
more »

2017-08-16 15:08 (2) Answers

How to make loops more efficient in R?

I am facing a problem with the large amount of time my code takes to run. I have one data frame with market capitalization of certain companies and I have a second data frame with ratios. Below there is a reproducible example AAPL <- c(500,550,60...
more »

2017-08-16 11:08 (2) Answers

RenderImage from URL and clickable

I would like to figure out how to use renderImage in Shiny with online located images (URL), and make the image clickable, so that I can hang an observeEvent() to it. I can do both these things, but not together. My approach to render an URL doesn't ...
more »

2017-08-16 10:08 (0) Answers

Stacking list column in data frame

I have the following data frame with list column: a <- data.frame(col1=c("a","b","c")) a$col2 <- list(list(),list(name="Michal", age=28), list(name="Johnny", age=31)) I'd like to merge these columns together as a data frame so the desired ou...
more »

2017-08-16 10:08 (3) Answers

Separating dates from text in R

I have a vector of strings that include a repeating pattern of start and end dates for variables collected at a site. Here is the first entry: "1942-10-06,1996-03-31Snow Depth (in/mm)1942-11-01,1996-03-31Snowfall (in/mm)1942-10-01,1997-12-27Growing...
more »

2017-08-15 23:08 (1) Answers

Iterate over pattern grep function in R

I am novice in R. I want to write the loop for the below code in R. day1<-XYZ[, -grep("_0", colnames(XYZ))] day2<-XYZ[, -grep("_0|_1", colnames(XYZ))] day3<-XYZ[, -grep("_0|_1|_2", colnames(XYZ))] day4<-XYZ[, -grep("_0|_1|_2|_3", colname...
more »

2017-08-15 17:08 (1) Answers

Combining two Weibull distributions in R

I am working on a project which involves combining two Weibull distributions and thus creating a double peaked curve. I then aim to make predictions using this. I have searched online and I can't seem to find anything on this or if R has a function t...
more »

2017-08-15 16:08 (1) Answers

Remove error bar ends in R using ggplot2

Using a sample dataframe: df <- structure(list(SITCD = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("GSO/TO", "IKOF", "JL", "MES", "SSD", "USSD"), class = "factor"), Code = structure(c(27L, 21L, 3L, 25L, 2...
more »

2017-08-15 14:08 (1) Answers

ggplot2 - Stacked bar with different width

I want to produce a reverse pyramid graph where the bar stacked on each other with different width. 1st, I have a stacked bar chart as below code sample library(dplyr) library(ggplot2) sample <- data_frame(x=c(1, 1, 1, 1, 2, 2, 2, 2), ...
more »

2017-08-15 12:08 (2) Answers

R: Convert Matrix to YES, NO dataframe

I have a matrix like this df <- matrix(c(rep(1,3),rep(2,3)),nrow=3,ncol=2) df: [,1] [,2] [1,] 1 2 [2,] 1 2 [3,] 1 2 I want to convert every cell value to YES, if greater than 0, else NO I understand that I can do this...
more »

2017-08-15 08:08 (2) Answers

Solving for two parameters using `optim()` in R?

I'm trying to find shape1 and shape2 in dbeta() such that the answer from dbeta() for the two input values: .6 and .8 become 3. I'm using the below optim() but don't get exact result, that is I expect getting values for shape1 and shape2 that when u...
more »

2017-08-15 01:08 (0) Answers