Posts by Clayton Stanley • 286 points
7 posts
-
2
votes3
answers611
viewsA: How to build time series with frequencies different from the original?
Or if you prefer the data.table package and some regex :) library(data.table) library(lubridate) library(stringr) dTbl = data.table(data=seq(dmy('01/01/1900'), dmy('31/12/2010'), by='1 day'),…
-
3
votes2
answers3134
viewsA: calculate difference between two dates in months on the R
I found the package mondate to do this: > library(mondate) > t2 = as.mondate('2015-03-17') > t1 = as.mondate('2014-01-07') > t2 - t1 Time difference of 14.32 months >…
-
3
votes3
answers1163
viewsA: How to separate a string from a certain line of a data.frame and at the same time create more rows?
Here is a solution using the data.table package > library(data.table) > dTbl <- data.table(x = 1:3, y = c("a", "d,e,f", "g,h")) > dTbl[, .(y=unlist(strsplit(y, ','))), by=x] x y 1: 1 a…
-
4
votes3
answers586
viewsA: Find files containing string and rename
If you have or can install the program rename and if all files are in the same directory: rename 's/xxxx.example.com/yyyy.superbubu.pt/' *
-
3
votes2
answers620
viewsA: How to smooth a curve and define ylim for a given function using ggplot2?
Here is an example code: x = seq(from=-4, to=4, length.out=1000) y = c(x^4 - 6*(x^2)) print(ggplot(data=data.frame(x=x, y=y), aes(x=x, y=y)) + geom_point(colour='red') + stat_smooth(se=F,…
-
0
votes3
answers517
viewsA: Comparing matrices of different sizes in R
You can do this with the package data.table: > library(data.table) > all_sec <- matrix(c("SEC1","SEC2","SEC3","SEC4","SEC5"),ncol=1) > portfolio <-…
-
2
votes2
answers969
viewsA: How to do an optimization with inequality restriction?
I am learning Portuguese, but this is a solution without inf explicita. ui = c(-1, -4) ci = c(-3) fr <- function(x) { x1 = x[1] x2 = x[2] -(5-(x1-2)^2-2*(x2-1)^2) } constrOptim(c(1.6,.2), fr,…