Re: [R] Transposing forecasts results from nnetar function and turn them into a data frame

2017-03-17 Thread Rui Barradas
Hello, By running the code of the OP, I've come to the conclusion that print.forecast calls print.data.frame: forecast:::print.forecast function (x, ...) { print(as.data.frame(x)) } But I'm unable to get what the OP wants by call as.data.frame(...). Here is the code with some made up da

Re: [R] Transposing forecasts results from nnetar function and turn them into a data frame

2017-03-17 Thread Paul Bernal
Dear Jim, Thank you for your valuable replies. So variable mf5 has the forecasts for a fitted nnetar model. Below is the class and the str(mf5) output. Maybe with this information I am sharing with you, hopefully you can give me some more guidance. Again, thank you so much! > class(mf5) [1] "fo

Re: [R] Transposing forecasts results from nnetar function and turn them into a data frame

2017-03-17 Thread Jim Lemon
Hi Paul, When manipulating any R object, the first thing to ascertain is what it is: class(TSmodelForecast) should give you useful information. str(TSmodelForecast) should give you more. Because of the wealth of defined data structures in R, it is difficult to manipulate them without this infor

[R] SOLVED: inadverted reordering of a df column when it is copied to another df

2017-03-17 Thread Karl Schilling
Dear All: it seems I have solved my reordering issue, and to thank all those who answered, I briefly list the mistake I made. I stared out from some data.frame holding values x and a grouping factor. Actually, my factor was a number (but not numeric) which was, however, not ordered. So it w

Re: [R] inadverted reordering of a df column when it is copied to another df

2017-03-17 Thread William Dunlap via R-help
But note that m:n does not always produce an integer sequence. It does when the output can be accurately represented as an integer sequence, it does not care if the inputs were integer or numeric. > class( (2^31-10):(2^31-2) ) [1] "integer" > class( (2^31-10):(2^31) ) # biggest integer is as

Re: [R] inadverted reordering of a df column when it is copied to another df

2017-03-17 Thread Rui Barradas
Hello, Not an answer to the OP's statement, but > class(1L:4L) [1] "integer" > class(1:4) [1] "integer" When using m:n there's no need for mL or nL. Rui Barradas Em 17-03-2017 16:58, Jeff Newmiller escreveu: Reprex confirming Bert: A <- data.frame( y = 1L:4L ) B <- data.frame(

Re: [R] lagging over consecutive pairs of rows in dataframe

2017-03-17 Thread Bert Gunter
Evan: Yes, I stand partially corrected. You have the concept correct, but R implements it differently than SAS. I think what you want for your approach is diff(): evens <- (seq_len(nrow(mydata)) %% 2) == 0 newdat <-data.frame(exp=mydata[evens,1 ],reslt= diff(mydata[,2])[evens[-1]]) ... which s

Re: [R] lagging over consecutive pairs of rows in dataframe

2017-03-17 Thread Bert Gunter
Evan: You misunderstand the concept of a lagged variable. Ulrik: Well, yes, that is certainly a general solution that works. However, given the *specific* structure described by the OP, an even more direct (maybe more efficient?) way to do it just uses (logical) subscripting: odds <- (seq_len(

Re: [R] lagging over consecutive pairs of rows in dataframe

2017-03-17 Thread Ulrik Stervbo
Hi Evan you can easily do this by applying diff() to each exp group. Either using dplyr: library(dplyr) mydata %>% group_by(exp) %>% summarise(difference = diff(rslt)) Or with base R aggregate(mydata, by = list(group = mydata$exp), FUN = diff) HTH Ulrik On Fri, 17 Mar 2017 at 17:34 Evan C

Re: [R] inadverted reordering of a df column when it is copied to another df

2017-03-17 Thread Jeff Newmiller
Reprex confirming Bert: A <- data.frame( y = 1L:4L ) B <- data.frame( x = 1L:4L ) A$x <- B$x plot(B$x) #' ![](http://i.imgur.com/cXSFsBh.png) Care to demonstrate for us, Karl? https://cran.r-project.org/web/packages/reprex/README.html On Fri, 17 Mar 2017, Bert Gunter wrote: You are

[R] lagging over consecutive pairs of rows in dataframe

2017-03-17 Thread Evan Cooch
Suppose I have a dataframe that looks like the following: n=2 mydata <- data.frame(exp = rep(1:5,each=n), rslt = c(12,15,7,8,24,28,33,15,22,11)) mydata exp rslt 11 12 21 15 327 428 53 24 63 28 74 33 84 15 95 22 10 5 11 The variabl

Re: [R] inadverted reordering of a df column when it is copied to another df

2017-03-17 Thread Thierry Onkelinx
Dear Karl, This is hard to investigate without a reproducible example. Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgiu

Re: [R] inadverted reordering of a df column when it is copied to another df

2017-03-17 Thread Bert Gunter
You are wrong. No reordering occurs. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Fri, Mar 17, 2017 at 8:05 AM, Karl Schilling wrote: > Dea

[R] inadverted reordering of a df column when it is copied to another df

2017-03-17 Thread Karl Schilling
Dear all: I have two data.frames A and B of the same number of rows (about 40,000). I realized that when I copy column x from data.frame A to B, the order of this column gets changed. This seems to affect only values in rownumbers > ~ 35/36,000. It also happens in any of the following three

Re: [R] add median value and standard deviation bar to lattice plot

2017-03-17 Thread Bert Gunter
If I understand you correcty, I suggest you consult a local statistician. Individual data points *cannot* have "confidence intervals." So you clearly need some statistical guidance, which is not what this list is about. Cheers, Bert Bert Gunter "The trouble with having an open mind is that peo

Re: [R] [FORGED] standard error for regression coefficients corresponding to factor levels

2017-03-17 Thread Doran, Harold
Just to do a better job in what is perhaps more "R-ish" w.r.t least squares calculations, here is perhaps a better example ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14) trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69) group <- gl(2, 10, 20, labels = c("Ctl","Trt")) weight

Re: [R] weird ggplot geom_segment behaviour

2017-03-17 Thread PIKAL Petr
Hi John Thierry already pointed me to propper direction. The key for such „zooming“ is to use coord_cartesian(xlim ...) which is stated, as I finally found, in xlim help page. Thanks Petr From: John Kane [mailto:jrkrid...@yahoo.ca] Sent: Friday, March 17, 2017 2:44 PM To: PIKAL Petr ; r-help@

Re: [R] weird ggplot geom_segment behaviour

2017-03-17 Thread John Kane via R-help
Hi Petr,It "seems" to be linked to the =/- 14 days that you are using for the limits. The code below should  restore one more bar. After that I don't know. p2 <- p+geom_segment(alpha=.4, size=3)+xlim(c(today()-21, today()+21))+   geom_vline(xintercept=as.numeric(today()), colour="pink", size=5)

Re: [R] weird ggplot geom_segment behaviour

2017-03-17 Thread PIKAL Petr
Dear Thierry Thanks, works great. My bad, after your advice I went through help page for xlim and found, that this behaviour is quite clearly stated there. I focused on geom_segment where I did not (obviously) find any clue. Best regards Petr > -Original Message- > From: Thierry Onkeli

Re: [R] Reversing table()

2017-03-17 Thread Mark Sharp
Kevin, The short answer is no. The function table() takes in the vectors provided as arguments, counts the number of occurrences of each category by adding the integer 1L to a bin (one for each category or factor level), and at the end it returns the counts in each bin. Since it does not retur

Re: [R] Reversing table()

2017-03-17 Thread PIKAL Petr
Is this what you want? http://opensourceconnections.com/blog/2016/09/17/expanding-data-frequency-table-r-stata/ Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Kevin E. > Thorpe > Sent: Friday, March 17, 2017 1:23 PM > To: r-help > Subj

Re: [R] weird ggplot geom_segment behaviour

2017-03-17 Thread Thierry Onkelinx
Dear Petr, Don't use xlim() but rather coord_cartesian(xlim = ...). See https://rpubs.com/INBOstats/zoom_in Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kl

[R] weird ggplot geom_segment behaviour

2017-03-17 Thread PIKAL Petr
Dear all I try to limit geom segment plot by xlim and encounter weird behaviour. Here is my data > dput(temp) temp <- structure(list(ukol = c("externí kalcinace", "povrchová úprava UVS30", "Testy mletí UVS30", "změna koncentrace olejových disperzí", "Mletí povrchově upravené UVS30", "mikronizace

[R] Reversing table()

2017-03-17 Thread Kevin E. Thorpe
I am wondering if there is a way to undo the results of table(). For example if you had a table that looked like the result of table(x, y) or table(x, y, z) is there a simple/elegant way to reverse the process to get the "original" x, y and z vectors? Thanks, Kevin -- Kevin E. Thorpe Head of

Re: [R] bnlearn impute problem

2017-03-17 Thread Marco Scutari
Dear Ross, On 17 March 2017 at 06:25, wrote: > I am having a problem running the "impute" function from the bnlearn > package. I assume you referred to the online documentation instead of the manuals that come with the package? I included impute() in bnlearn 4.1, so you will have to upgrade to

Re: [R] [FORGED] standard error for regression coefficients corresponding to factor levels

2017-03-17 Thread Doran, Harold
A slightly more ³R-ish² way of doing S <- solve(t(X)%*%X) Is to instead use S <- solve(crossprod(X)) And the idea idea of inverting the SSCP matrix only and not actually solving the linear system is not so great, which is why it is better to do as Rolf is suggesting and get all things you need

Re: [R] add median value and standard deviation bar to lattice plot

2017-03-17 Thread Luigi Marongiu
dear Bert, the code as I read it draws 30 median lines, one for each cluster. what I am looking for is a function that will plot 190 individual confidence intervals, one for each measurement. would the code cover even that instance? regards luigi On Thu, Mar 16, 2017 at 2:41 PM, Bert Gunter wrote

Re: [R] Percent transformation

2017-03-17 Thread Christoph Puschmann
Dear All, Thank you for helping me out. First, I am sorry for adding a HTML element. I was not aware of it. I simply copy and pasted the output of mat_data from R studio. Second, no it is not homework. It was part of a side project at work. Third, thank you Jeff. Your comment was really produc