Posts by Robert • 887 points
37 posts
-
2
votes1
answer56
viewsA: Name columns generated by Summarise() and use division in the same function
Uses `mutate; media_diaria_divisao <- df %>% mutate(x3_x4=x3/x4) %>% group_by(mes) %>% summarise_at(vars(x1,x4,x3_x4), mean, na.rm = TRUE) soma_mensal_div <- df %>%…
-
1
votes1
answer108
viewsA: Transform XML into Dataframe
You can try it that way: library(XML) doc<-xmlParse("base.xml") nodes = getNodeSet(doc, "//test:house//test:billing//test:proceduresummary") df=xmlToDataFrame(nodes=nodes ,stringsAsFactors = F)…
-
0
votes1
answer37
viewsA: nloptr optimization - "objective in x0 Returns NA" error
It is difficult to understand this function. It follows a code that works, but not if you do what you want. E_p= function(Ee_m,p,y=y) -(sum(y)/Ee_m)*(funcao_f(Ee_m,p) -…
-
0
votes1
answer83
viewsA: Pause loop of a gif
Adds wrap = FALSE the ggplot animation. For example transition_states(gear, transition_length = 2, state_length = 1,wrap = FALSE)
-
1
votes1
answer47
viewsA: BEKK Multivariate Garch Error in R
The function simulateBEKK is to simulate series simulateBEKK(series.count, T, order = c(1, 1), params = NULL) To estimate uses the function BEKK BEKK(eps, order = c(1, 1), params = NULL, fixed =…
-
2
votes1
answer198
viewsA: Filter a data frame by a column values
If you are sure that the first line with replicated ID is the latest, and you want to keep that line, your code already does that, keep the first line of the repeated ID. You can check with this…
-
3
votes1
answer115
viewsA: How to proceed non-linear regression by the mitscherlich model?
The setting is not good but follows: fm <- nls(COM ~ Alfa*(1-10^(-Gama*(TEMPO+Tetha))), data = dados, start = list(Alfa = 900, Gama = .1, Tetha = 1)) summary(fm) # Parameters: # Estimate Std.…
-
1
votes1
answer46
viewsA: Comparison of two curves
If you do summary(C1) will have the similar result: # Coefficients: # Estimate Std. Error t value Pr(>|t|) # (Intercept) 9.72936 0.58273 16.70 <2e-16 *** # x 2.01814 0.02864 70.47 <2e-16…
-
3
votes1
answer656
viewsA: Insert more than one line into a chart in the R
Tries to format your series as xts: base$km_media_dia=as.numeric(base$km_media_dia) #options(digits.secs=3) base$data=as.POSIXct(base$data, format = "%Y-%m-%d %H:%M:%OS") #format.Date(base$data)…
-
3
votes1
answer3263
viewsA: How to insert point and line caption in ggplot?
An alternative: library(reshape) dados1=melt(dados,id=c(1),c("total1","total2")) dados1$value[dados1$variable=="total2"]=dados1$value[dados1$variable=="total2"]*14 names(dados1)[2]="Legenda"…
-
2
votes1
answer77
viewsA: Plotting data evolution in time on R
Would that be: #aumentar os dados para mais meses: orcamento_filtrado<-rbind(orcamento_filtrado,orcamento_filtrado) orcamento_filtrado<-rbind(orcamento_filtrado,orcamento_filtrado)…
-
1
votes1
answer132
views -
1
votes2
answers547
viewsA: Image and text in Latex
Use the "float" package and the [H] option for your pictures. \usepackage{float} ... \begin{figure}[H] \centering \includegraphics{suafigura} \caption{Algum título} \label{figxx} \end{figure}…
-
1
votes2
answers71
viewsA: Calculate the product of an operation between two dataframes conditionally
A proposal using basic R. I made a change in Dfs to simulate more real cases where there is data that is not in both Dfs set.seed(123)…
-
0
votes2
answers97
viewsA: How to run a model for each subset of data of a time series to see
I invented data and a function, but you can use the same logic: set.seed(123) table1 = data.frame(Animal=rep(1:6,each=10),Dia=rep(1:4,15), Consumo=round(runif(60,240,500),0)) runDLM =…
-
2
votes2
answers2458
viewsA: Concatenate values within the same data frame columns in R software
Search the fa function help paste. If your data frame is df can do: re1<- apply(df[1:3,-1],2,paste,collapse="_") nomes<- c(df[3,1],re1) Novo df: df1 <- df[-c(1:3),] colnames(df1)<- nomes…
-
1
votes2
answers415
viewsA: Import, read and convert cross data to a data frame.
Reading is no problem, you can use read.table with Skip =2 parameter, to skip the first 2 lines, and read the data from a csv file. Then you can use reshape reshape2 to put bank in long format.…
-
1
votes1
answer54
viewsA: How to send data from data frames in optimized R code questions?
A proposal: dfCode2 <- function(df) { if(!is.data.frame(df)) {return(-1)} k <- "df <- data.frame(" tcs=sapply(colnames(df),function(co) { tc=df[,co] # open column vector ks <-…
-
1
votes1
answer44
viewsA: Accrued Interest Quarterly using R
Try this: library(zoo) jt=rollapply(juros,3,function(x)prod(1+x)-1,by=3,align="right") jurost=ts(na.omit(as.numeric(jt)),end=c(2009,3),frequency = 4) jurost plot(jurost)…
-
1
votes1
answer77
viewsA: R - match and add string
The following code performs the following: for each item in each column, retrieves the names, searches them in the vector n, for the names found checks whether they already act in the company, and…
-
3
votes2
answers94
viewsA: Organize Results Kalman Filter in a Matrix
If your function otimizar inside optim is funcao_otimazarei, can solve using lapply and sapply (where a function, which usually returns several data structures, is applied to each column).…
-
0
votes1
answer2394
viewsA: How to use the "print" command to show string variables together with integers in MATLAB?
Try this: meses = {'Janeiro','Fevereiro','Março','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'}; mesdata = cellstr(meses) prompt = 'Valor de 1 a 12: '; mes =…
-
3
votes2
answers64
viewsA: R - match and replace string
Try something similar: ns<-sapply(n,function(nx) unlist(strsplit(nx," (",fixed=T)) ) ns<-t(unique(ns)) row.names(ns)<-NULL res<-apply(ns,2,unique) res[[2]]<-gsub("\\)","",res[[2]])…
-
1
votes2
answers2571
viewsA: Bar graph - ggplot2
Try this: df <- data.frame(CID = c("A", "A", "B", "C", "C", "Z"), AFASTAMENTOS = c(2,3,5,8,9, 12), ATENDIMENTOS = c(21, 32, 4, 6, 7, 43), stringsAsFactors = FALSE ) # acumular por CID…
-
1
votes1
answer6249
viewsA: Insert caption footnote in Latex
Try with \footnotemark and \footnotetext on the same page: \begin{figure}[!tbp] \centering \subfloat[Visualização do conjunto.]{\includegraphics[width=0.4\textwidth]{foo}\label{fig:exmplo_1}} \hfill…
-
8
votes1
answer2268
viewsA: In R, using the plotly package, can I plot the map of Brazil and its states?
Using data from the package maps you have the cities: library(maps) dfb<-world.cities[world.cities$country.etc=="Brazil",] library(plotly) dfb$hover <- paste(dfb$name, "Pop", dfb$pop/1e6, "…
-
2
votes1
answer2121
viewsA: How to make turn ROC - AUC reversed in R?
With Dropbox data and original code the chart is normal. > unlist([email protected]) [1] 0.7518116…
-
1
votes1
answer531
viewsA: Impulse-Response function in R
Apparently ortho = TRUE/FALSE serves to control a possible autocorrelation between variables (or their errors), making the marginal effect "cleaner". This is accomplished internally by adjusting…
-
0
votes1
answer36
viewsA: Access objects of the formula class
Try this: e <- new.env() a <- list() b <- list() set.seed(123) a[[1]] <- matrix(rnorm(20), 2) b[[1]] <- matrix(rnorm(20), 2) e$a <- a e$b <- b…
-
2
votes1
answer179
viewsA: Problem loading winbugs into R
Already tried to run R as administrator?…
-
0
votes2
answers81
viewsA: Obtain the Summary of the results from the use of the LOESS
You have to post a playable code. You can try: cbind(xl,y.predict) # a curva cbind(xl[infl ], y.predict[infl ]) # os pontos max/min
-
1
votes1
answer243
viewsA: Best value for span/f parameter in lowess/loess function in R
It would be good to post what the purpose of doing this, it may be that loess functions are not the best solution. The goal of this type of function is usually not to achieve the greatest adjustment…
-
0
votes1
answer113
viewsA: Use regression residues to calculate another regression (within the function) in R
The code has several errors. The function produces results, but I don’t know if what you’re trying to do. # simulando dados set.seed(123) e=rnorm(50) a=runif(50,2,6)+2*e;lat=rnorm(50,3,.5)…
-
0
votes1
answer85
viewsA: Operation with large matrix
The question is how to define a matrix a appropriate. Use: N=2000 a = matrix(rnorm(N*2*8), ncol = 8) #b = a[1:N, ] #para fazer a questão mais desafiadora pode definir b com linhas aleatórias de a b…
-
0
votes2
answers935
viewsA: How to forecast future values of a time series?
The critical point to predict is to calculate series autocorrelation. This is how past values influence the determination of future values. Then you have to analyze whether this relationship is…
-
1
votes2
answers3369
viewsA: How to do Multiple Linear Regression?
I’ll generate a random RV variable to show the procedure. To determine the number of lags you have to do some tests, you can search some text or here in the OS. For example this %# Gerar uma…
-
1
votes1
answer492
viewsA: Operation with three-dimensional arrays
Try this! di=6 dk=5 dl=4 set.seed(234) dados <- round(rnorm(di*dk*dl,20,5)); mD <- array(dados, c(di, dk, dl)); mD[di,dk,dl-1] <- 24; #subst 18 pk=1:di lp=1:dl…