[R] RSA package adjust alpha for a1-a4 confidence intervals
Hi, I'm not experienced with R at all. I'm using some canned code to produce RSA models in the RSA package. I'd like to be able to adjust the alpha for the a1-a4 confidence intervals. This doesn't appear to be a native option for the RSA package, unless I'm missing something because I'm a novice. Is there an easy way to do this? Any advice would be appreciated, thanks for your time in advance! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to create a plot of permutation of 30 random values and show proportion of values
Hi Ana, Yes, this makes more sense. A bar plot of the number of simulations performed by the proportion of SNPs with q-value < 0.05. I would expect the axes to be swapped, but my notion that you would want to know the proportion (DV) for a given number of simulations (IV) may well be wrong. Jim On Fri, Jan 24, 2020 at 3:00 PM Ana Marija wrote: > > Hi Jim, > > thanks for getting back to me. > Can you please confirm if you can see this plot in attach? > > > Thanks > Ana > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to create a plot of permutation of 30 random values and show proportion of values
Hi Jim, thanks for getting back to me. Can you please confirm if you can see this plot in attach? Thanks Ana On Thu, Jan 23, 2020 at 8:06 PM Jim Lemon wrote: > > Hi Ana, > You seem to be working on an identification or classification problem. > Your sample plot didn't come through, perhaps try converting it to a > PDF or PNG. > I may be missing something, but I can't see how randomly selecting 30 > values from almost 4 million is going to mean anything in terms of > statistical significance. I hope you will pardon me for saying that it > looks like a "p-trawl". It is easy to select cases where the p-value > is less than 0.05: > > a[a$pvalue < 0.05,] > > Maybe what you want to do is display this subset of your data as > candidates for a match among the very large number of non-matches. > Let's do a bit of damage to your sample data and add the proportions: > > a<-read.table(text="rs pvalue pSNP > rs185642176 0.0267407 0.6 > rs184120752 0.0787681 0.3 > rs10904045 0.0508162 0.4 > rs35849539 0.0875910 0.2 > rs141633513 0.0787759 0.2 > rs4468273 0.0542171 0.4 > rs4567378 0.0539484 0.4 > rs7084251 0.0126445 0.7 > rs181605000 0.0787838 0.35 > rs12255619 0.0192719 0.61 > rs140367257 0.0788008 0.25 > rs10904178 0.0969814 0.16 > rs7918960 0.0436341 0.45 > rs61688896 0.0526256 0.39 > rs151283848 0.0787284 0.34 > rs140174295 0.0989107 0.11 > rs145945079 0.0787015 0.23 > rs4881370 0.0455089 0.51 > rs183895035 0.0787015 0.22 > rs181749526 0.0787015 0.22", > header=TRUE,stringsAsFactors=FALSE) > alt05<-a[a$pvalue < 0.05,] > library(plotrix) > segmat<-matrix(c(alt05$pSNP,alt05$pSNP-0.1,alt05$pSNP+0.1,rep(1,5)), > nrow=4,byrow=TRUE) > rownames(segmat)<-c("prop","lower","upper","N") > centipede.plot(segmat,mar=c(4,6,3,4), > main="Proportion of SNPs", > left.labels=alt05$rs,right.labels=rep("",5)) > > This is probably not what you want, but it is a start. > > Jim > > On Fri, Jan 24, 2020 at 7:08 AM Ana Marija > wrote: > > > > Hello, > > > > I have a data frame which looks like this: > > > > > head(a,20) > > rs pvalue > > 1: rs185642176 0.267407 > > 2: rs184120752 0.787681 > > 3: rs10904045 0.508162 > > 4: rs35849539 0.875910 > > 5: rs141633513 0.787759 > > 6: rs4468273 0.542171 > > 7: rs4567378 0.539484 > > 8: rs7084251 0.126445 > > 9: rs181605000 0.787838 > > 10: rs12255619 0.192719 > > 11: rs140367257 0.788008 > > 12: rs10904178 0.969814 > > 13: rs7918960 0.436341 > > 14: rs61688896 0.526256 > > 15: rs151283848 0.787284 > > 16: rs140174295 0.989107 > > 17: rs145945079 0.787015 > > 18: rs4881370 0.455089 > > 19: rs183895035 0.787015 > > 20: rs181749526 0.787015 > > > dim(a) > > [1] 3859763 2 > > > > What I would like to do is to take random subsets of 30 of those rs > > throughout the dataframe and find out which subsets of those generated > > have FDR value <0.05 > > > > FDR I would calculate I guess with: > > a$fdr=p.adjust(a$pvalue,method="BH") > > > > but I also guess I would be calculating only FDR for a particular > > subset of 30 randomly chosen rs, not for the whole data set. > > > > The result I would like to present like in the attached plot. The > > x-axis say proportion of SNPs and in my case SNP is equivalent to rs > > > > Can you please help with this, I really don't have idea how to go about > > this. > > > > Thanks > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to create a plot of permutation of 30 random values and show proportion of values
Hi Ana, You seem to be working on an identification or classification problem. Your sample plot didn't come through, perhaps try converting it to a PDF or PNG. I may be missing something, but I can't see how randomly selecting 30 values from almost 4 million is going to mean anything in terms of statistical significance. I hope you will pardon me for saying that it looks like a "p-trawl". It is easy to select cases where the p-value is less than 0.05: a[a$pvalue < 0.05,] Maybe what you want to do is display this subset of your data as candidates for a match among the very large number of non-matches. Let's do a bit of damage to your sample data and add the proportions: a<-read.table(text="rs pvalue pSNP rs185642176 0.0267407 0.6 rs184120752 0.0787681 0.3 rs10904045 0.0508162 0.4 rs35849539 0.0875910 0.2 rs141633513 0.0787759 0.2 rs4468273 0.0542171 0.4 rs4567378 0.0539484 0.4 rs7084251 0.0126445 0.7 rs181605000 0.0787838 0.35 rs12255619 0.0192719 0.61 rs140367257 0.0788008 0.25 rs10904178 0.0969814 0.16 rs7918960 0.0436341 0.45 rs61688896 0.0526256 0.39 rs151283848 0.0787284 0.34 rs140174295 0.0989107 0.11 rs145945079 0.0787015 0.23 rs4881370 0.0455089 0.51 rs183895035 0.0787015 0.22 rs181749526 0.0787015 0.22", header=TRUE,stringsAsFactors=FALSE) alt05<-a[a$pvalue < 0.05,] library(plotrix) segmat<-matrix(c(alt05$pSNP,alt05$pSNP-0.1,alt05$pSNP+0.1,rep(1,5)), nrow=4,byrow=TRUE) rownames(segmat)<-c("prop","lower","upper","N") centipede.plot(segmat,mar=c(4,6,3,4), main="Proportion of SNPs", left.labels=alt05$rs,right.labels=rep("",5)) This is probably not what you want, but it is a start. Jim On Fri, Jan 24, 2020 at 7:08 AM Ana Marija wrote: > > Hello, > > I have a data frame which looks like this: > > > head(a,20) > rs pvalue > 1: rs185642176 0.267407 > 2: rs184120752 0.787681 > 3: rs10904045 0.508162 > 4: rs35849539 0.875910 > 5: rs141633513 0.787759 > 6: rs4468273 0.542171 > 7: rs4567378 0.539484 > 8: rs7084251 0.126445 > 9: rs181605000 0.787838 > 10: rs12255619 0.192719 > 11: rs140367257 0.788008 > 12: rs10904178 0.969814 > 13: rs7918960 0.436341 > 14: rs61688896 0.526256 > 15: rs151283848 0.787284 > 16: rs140174295 0.989107 > 17: rs145945079 0.787015 > 18: rs4881370 0.455089 > 19: rs183895035 0.787015 > 20: rs181749526 0.787015 > > dim(a) > [1] 3859763 2 > > What I would like to do is to take random subsets of 30 of those rs > throughout the dataframe and find out which subsets of those generated > have FDR value <0.05 > > FDR I would calculate I guess with: > a$fdr=p.adjust(a$pvalue,method="BH") > > but I also guess I would be calculating only FDR for a particular > subset of 30 randomly chosen rs, not for the whole data set. > > The result I would like to present like in the attached plot. The > x-axis say proportion of SNPs and in my case SNP is equivalent to rs > > Can you please help with this, I really don't have idea how to go about this. > > Thanks > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to create a plot of permutation of 30 random values and show proportion of values
Hello, I have a data frame which looks like this: > head(a,20) rs pvalue 1: rs185642176 0.267407 2: rs184120752 0.787681 3: rs10904045 0.508162 4: rs35849539 0.875910 5: rs141633513 0.787759 6: rs4468273 0.542171 7: rs4567378 0.539484 8: rs7084251 0.126445 9: rs181605000 0.787838 10: rs12255619 0.192719 11: rs140367257 0.788008 12: rs10904178 0.969814 13: rs7918960 0.436341 14: rs61688896 0.526256 15: rs151283848 0.787284 16: rs140174295 0.989107 17: rs145945079 0.787015 18: rs4881370 0.455089 19: rs183895035 0.787015 20: rs181749526 0.787015 > dim(a) [1] 3859763 2 What I would like to do is to take random subsets of 30 of those rs throughout the dataframe and find out which subsets of those generated have FDR value <0.05 FDR I would calculate I guess with: a$fdr=p.adjust(a$pvalue,method="BH") but I also guess I would be calculating only FDR for a particular subset of 30 randomly chosen rs, not for the whole data set. The result I would like to present like in the attached plot. The x-axis say proportion of SNPs and in my case SNP is equivalent to rs Can you please help with this, I really don't have idea how to go about this. Thanks __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error with constrained curve fitting through specific points
Thanks Rui and everyone for your help! Using ` constraint = "increase"` and `lambda = 0.1` did it. If we ignore the first point, `lambda = -1` option is also possible. `cobs` will automatically choose a lambda value plot(fit_result) summary(fit_result) # COBS smoothing spline (degree = 2) from call: # cobs(x = dat$x, y = dat$y, constraint = "increase", lambda = -1, pointwise = con) # {tau=0.5}-quantile; dimensionality of fit: 29 from {29} # x$knots[1:9]: -6.0e-06, 2.5e-01, 5.0e-01, ... , 6.0e+00 # lambda = 1.4494, selected via SIC, out of 25 ones. # with 10 pointwise constraints # coef[1:11]: -6.1866e-05, 1.1065e+00, 2.7435e+00, 3.1815e+00, 3.7572e+00, ... , 1.9183e+01 # R^2 = 100% ; empirical tau (over all): 5/10 = 0.5 (target tau= 0.5) Best, -- Tung On Wed, Jan 22, 2020 at 9:39 AM Rui Barradas wrote: > Hello, > > This seems to "work". It doesn't give errors nor warnings and the fitted > line passes through the given points. > > > fit_result <- cobs(dat$x, dat$y, > constraint = "increase", > lambda = 0.1, > pointwise = con) > > plot(y~x, dat) > pred <- predict(fit_result) > lines(pred[,1], pred[,2], col = "red") > > > Hope this helps, > > Rui Barradas > > Às 15:00 de 22/01/20, Tung Nguyen escreveu: > > Hello R-Help, > > > > I'm trying to find the best fitting curve through a given set of points. > > The fitted curve must also pass through these points. I found an answer > on > > Cross Validated which suggested to use the `cobs: Constrained B-Splines > > (Sparse Matrix Based)` package. However, I got an error while testing it > > with my sample data: > > > > Error in x %*% coefficients: NA/NaN/Inf in foreign function call (arg 2) > > > > *My question*: what caused this error and how can I fix it? Any > suggestion > > is greatly appreciated. Thanks! > > > > library(cobs) > > > > dat <- data.frame( > >x = c(1e-06,0.25,0.5,0.75,1,2,3,4,5,6), > >y = c(1e-07,1.925,2.9625,3.469375, > > 3.875,4.5315,4.89,5.09375,5.216,5.46)) > > dat > > #> x y#> 1 1.0e-06 0.001#> 2 2.5e-01 > > 1.925#> 3 5.0e-01 2.9625000#> 4 7.5e-01 3.4693750#> 5 1.0e+00 > > 3.875#> 6 2.0e+00 4.5315000#> 7 3.0e+00 4.890#> 8 4.0e+00 > > 5.0937500#> 9 5.0e+00 5.216#> 10 6.0e+00 5.460 > > # visual inspection > > plot(dat); lines(dat) > > > > # define constrained points > > con <- matrix( > >cbind(c(0,0,0,0,0,0,0,0,0,0), > > c(1e-06,0.25,0.5,0.75,1,2,3, 4,5,6), > > c(1e-07,1.925,2.9625,3.469375, > >3.875,4.5315,4.89,5.09375,5.216, 5.46)), > >ncol = 3, nrow = 10) > > # curve fitting > > fit_result <- cobs(dat$x, dat$y, pointwise = con)*#> qbsks2(): > > #> Performing general knot selection ... > > #> Error in x %*% coefficients: NA/NaN/Inf in foreign function call (arg > 2)* > > > > > > Best regards, > > > > -- Tung > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Convert Long DOY time format to yyyymmdd hh format: Problem Fixed
Dear Gurus, I am so happy to thank you all for your great help!!! Jim's code first did it. Thanks again to everyone. Warmest regards Ogbos On Thu, Jan 23, 2020 at 10:42 AM Jim Lemon wrote: > > Hi Ogbos, > Try this: > > oodates<-read.table(text="1963 335 0 > 1963 335 1 > 1963 335 2 > 1963 335 3 > 1963 335 4 > 1963 335 5 > 1963 335 6 > 1963 335 7 > 1963 335 8 > 1963 335 9 > 1996 202 20 > 1996 202 21 > 1996 202 22 > 1996 202 23 > 1996 203 0 > 1996 203 1 > 1996 203 2 > 1996 203 3 > 2018 365 20 > 2018 365 21 > 2018 365 22 > 2018 365 23") > oodates$Pdate<-strptime(paste(oodates[,1],oodates[,2],oodates[,3]), > format="%Y %j %H") > > Jim > > On Thu, Jan 23, 2020 at 8:24 PM Ogbos Okike wrote: > > > > Dear Experts, > > I have a data spanning 56 years from 1963 to 2018. > > The datetime format is in DOY hour: > > 1963 335 0 > > 1963 335 1 > > 1963 335 2 > > 1963 335 3 > > 1963 335 4 > > 1963 335 5 > > 1963 335 6 > > 1963 335 7 > > 1963 335 8 > > 1963 335 9 > > 1996 202 20 > > 1996 202 21 > > 1996 202 22 > > 1996 202 23 > > 1996 203 0 > > 1996 203 1 > > 1996 203 2 > > 1996 203 3 > > 2018 365 20 > > 2018 365 21 > > 2018 365 22 > > 2018 365 23 > > When I used: > > as.Date(335,origin="1963-01-01"), for the first row, I got: > > [1] "1963-12-02" > > This is the format I want, though it is not yet complete. Time is missing. > > > > Again, I can't be doing this one after the other. I guess you have a > > better way of handling this. I have spent some time trying to get it > > right but I am really stuck. I would be most glad if you could spare > > your busy time to help me again. > > > > Thank you very much for your usual kind assistance. > > > > Best regards > > Ogbos > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Convert Long DOY time format to yyyymmdd hh format
Jim's (and Petr's) solution wins -pd > On 23 Jan 2020, at 10:56 , peter dalgaard wrote: > > Here's an idea: > >> as.POSIXct(paste0("1963","-1-1"))+as.difftime(335,units="days") + >> as.difftime(3, units="hours") > [1] "1963-12-02 03:00:00 CET" > > However, 2 caveats > > (a) I think you need to subtract 1 from the DOY (1 should be Jan 1, right?) > (b) Beware Daylight Savings time: > >> as.POSIXct(paste0("2019","-1-1"))+as.difftime(160,units="days") + >> as.difftime(3, units="hours") > [1] "2019-06-10 04:00:00 CEST" > > This can be worked around as follows: > >> tt <- as.POSIXct(paste0("2019","-1-1"))+as.difftime(160,units="days") >> ttl <- as.POSIXlt(tt) >> ttl$hour=0 >> ttl + as.difftime(3, units="hours") > [1] "2019-06-10 03:00:00 CEST" > > ISOdate() and ISOdatetime() can also be used, again beware of time zones and > DST. Also, ISOdate gives 12:00 GMT, whereas the POSIX stuff gives 0:00. > > -pd > >> On 23 Jan 2020, at 10:24 , Ogbos Okike wrote: >> >> Dear Experts, >> I have a data spanning 56 years from 1963 to 2018. >> The datetime format is in DOY hour: >> 1963 335 0 >> 1963 335 1 >> 1963 335 2 >> 1963 335 3 >> 1963 335 4 >> 1963 335 5 >> 1963 335 6 >> 1963 335 7 >> 1963 335 8 >> 1963 335 9 >> 1996 202 20 >> 1996 202 21 >> 1996 202 22 >> 1996 202 23 >> 1996 203 0 >> 1996 203 1 >> 1996 203 2 >> 1996 203 3 >> 2018 365 20 >> 2018 365 21 >> 2018 365 22 >> 2018 365 23 >> When I used: >> as.Date(335,origin="1963-01-01"), for the first row, I got: >> [1] "1963-12-02" >> This is the format I want, though it is not yet complete. Time is missing. >> >> Again, I can't be doing this one after the other. I guess you have a >> better way of handling this. I have spent some time trying to get it >> right but I am really stuck. I would be most glad if you could spare >> your busy time to help me again. >> >> Thank you very much for your usual kind assistance. >> >> Best regards >> Ogbos >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > -- > Peter Dalgaard, Professor, > Center for Statistics, Copenhagen Business School > Solbjerg Plads 3, 2000 Frederiksberg, Denmark > Phone: (+45)38153501 > Office: A 4.23 > Email: pd@cbs.dk Priv: pda...@gmail.com > > > > > > > > > -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Convert Long DOY time format to yyyymmdd hh format
Here's an idea: > as.POSIXct(paste0("1963","-1-1"))+as.difftime(335,units="days") + > as.difftime(3, units="hours") [1] "1963-12-02 03:00:00 CET" However, 2 caveats (a) I think you need to subtract 1 from the DOY (1 should be Jan 1, right?) (b) Beware Daylight Savings time: > as.POSIXct(paste0("2019","-1-1"))+as.difftime(160,units="days") + > as.difftime(3, units="hours") [1] "2019-06-10 04:00:00 CEST" This can be worked around as follows: > tt <- as.POSIXct(paste0("2019","-1-1"))+as.difftime(160,units="days") > ttl <- as.POSIXlt(tt) > ttl$hour=0 > ttl + as.difftime(3, units="hours") [1] "2019-06-10 03:00:00 CEST" ISOdate() and ISOdatetime() can also be used, again beware of time zones and DST. Also, ISOdate gives 12:00 GMT, whereas the POSIX stuff gives 0:00. -pd > On 23 Jan 2020, at 10:24 , Ogbos Okike wrote: > > Dear Experts, > I have a data spanning 56 years from 1963 to 2018. > The datetime format is in DOY hour: > 1963 335 0 > 1963 335 1 > 1963 335 2 > 1963 335 3 > 1963 335 4 > 1963 335 5 > 1963 335 6 > 1963 335 7 > 1963 335 8 > 1963 335 9 > 1996 202 20 > 1996 202 21 > 1996 202 22 > 1996 202 23 > 1996 203 0 > 1996 203 1 > 1996 203 2 > 1996 203 3 > 2018 365 20 > 2018 365 21 > 2018 365 22 > 2018 365 23 > When I used: > as.Date(335,origin="1963-01-01"), for the first row, I got: > [1] "1963-12-02" > This is the format I want, though it is not yet complete. Time is missing. > > Again, I can't be doing this one after the other. I guess you have a > better way of handling this. I have spent some time trying to get it > right but I am really stuck. I would be most glad if you could spare > your busy time to help me again. > > Thank you very much for your usual kind assistance. > > Best regards > Ogbos > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Convert Long DOY time format to yyyymmdd hh format
Hi as.Date converts to dates (without hours), which is clearly stated in the first line of documentation. If you want include hour you should use ?strptime Something like > strptime("1963 335 1", format="%Y %j %H") [1] "1963-12-01 01:00:00 CET" You definitely does not need to do it one by one, but exact way depends on how does the object look like in R. Cheers Petr > -Original Message- > From: R-help On Behalf Of Ogbos Okike > Sent: Thursday, January 23, 2020 10:24 AM > To: r-help > Subject: [R] Convert Long DOY time format to mmdd hh format > > Dear Experts, > I have a data spanning 56 years from 1963 to 2018. > The datetime format is in DOY hour: > 1963 335 0" > 1963 335 1 > 1963 335 2 > 1963 335 3 > 1963 335 4 > 1963 335 5 > 1963 335 6 > 1963 335 7 > 1963 335 8 > 1963 335 9 > 1996 202 20 > 1996 202 21 > 1996 202 22 > 1996 202 23 > 1996 203 0 > 1996 203 1 > 1996 203 2 > 1996 203 3 > 2018 365 20 > 2018 365 21 > 2018 365 22 > 2018 365 23 > When I used: > as.Date(335,origin="1963-01-01"), for the first row, I got: > [1] "1963-12-02" > This is the format I want, though it is not yet complete. Time is missing. > > Again, I can't be doing this one after the other. I guess you have a better way > of handling this. I have spent some time trying to get it right but I am really > stuck. I would be most glad if you could spare your busy time to help me > again. > > Thank you very much for your usual kind assistance. > > Best regards > Ogbos > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Convert Long DOY time format to yyyymmdd hh format
Hi Ogbos, Try this: oodates<-read.table(text="1963 335 0 1963 335 1 1963 335 2 1963 335 3 1963 335 4 1963 335 5 1963 335 6 1963 335 7 1963 335 8 1963 335 9 1996 202 20 1996 202 21 1996 202 22 1996 202 23 1996 203 0 1996 203 1 1996 203 2 1996 203 3 2018 365 20 2018 365 21 2018 365 22 2018 365 23") oodates$Pdate<-strptime(paste(oodates[,1],oodates[,2],oodates[,3]), format="%Y %j %H") Jim On Thu, Jan 23, 2020 at 8:24 PM Ogbos Okike wrote: > > Dear Experts, > I have a data spanning 56 years from 1963 to 2018. > The datetime format is in DOY hour: > 1963 335 0 > 1963 335 1 > 1963 335 2 > 1963 335 3 > 1963 335 4 > 1963 335 5 > 1963 335 6 > 1963 335 7 > 1963 335 8 > 1963 335 9 > 1996 202 20 > 1996 202 21 > 1996 202 22 > 1996 202 23 > 1996 203 0 > 1996 203 1 > 1996 203 2 > 1996 203 3 > 2018 365 20 > 2018 365 21 > 2018 365 22 > 2018 365 23 > When I used: > as.Date(335,origin="1963-01-01"), for the first row, I got: > [1] "1963-12-02" > This is the format I want, though it is not yet complete. Time is missing. > > Again, I can't be doing this one after the other. I guess you have a > better way of handling this. I have spent some time trying to get it > right but I am really stuck. I would be most glad if you could spare > your busy time to help me again. > > Thank you very much for your usual kind assistance. > > Best regards > Ogbos > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Convert Long DOY time format to yyyymmdd hh format
Quoting Ogbos Okike : Dear Experts, I have a data spanning 56 years from 1963 to 2018. The datetime format is in DOY hour: 1963 335 0 1963 335 1 1963 335 2 1963 335 3 1963 335 4 1963 335 5 1963 335 6 1963 335 7 1963 335 8 1963 335 9 1996 202 20 1996 202 21 1996 202 22 1996 202 23 1996 203 0 1996 203 1 1996 203 2 1996 203 3 2018 365 20 2018 365 21 2018 365 22 2018 365 23 When I used: as.Date(335,origin="1963-01-01"), for the first row, I got: [1] "1963-12-02" This is the format I want, though it is not yet complete. Time is missing. Again, I can't be doing this one after the other. I guess you have a better way of handling this. I have spent some time trying to get it right but I am really stuck. I would be most glad if you could spare your busy time to help me again. Thank you very much for your usual kind assistance. Best regards Ogbos Perhaps something like this: read.table(text=" 1963 335 0 1963 335 1 1963 335 2 1963 335 3 1963 335 4 1963 335 5 1963 335 6 1963 335 7 1963 335 8 1963 335 9 1996 202 20 1996 202 21 1996 202 22 1996 202 23 1996 203 0 1996 203 1 1996 203 2 1996 203 3 2018 365 20 2018 365 21 2018 365 22 2018 365 23 ", header = FALSE, sep = " ") -> data as.POSIXct(paste(as.Date(paste0(data[[1]], "-1-1")) + data[[2]] - 1, data[[3]]), format = "%Y-%m-%d %H") You might want to specify a different timezone, and also check for "off-by-one" error when it comes to day of year. -- Enrico Schumann Lucerne, Switzerland http://enricoschumann.net __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Convert Long DOY time format to yyyymmdd hh format
Dear Experts, I have a data spanning 56 years from 1963 to 2018. The datetime format is in DOY hour: 1963 335 0 1963 335 1 1963 335 2 1963 335 3 1963 335 4 1963 335 5 1963 335 6 1963 335 7 1963 335 8 1963 335 9 1996 202 20 1996 202 21 1996 202 22 1996 202 23 1996 203 0 1996 203 1 1996 203 2 1996 203 3 2018 365 20 2018 365 21 2018 365 22 2018 365 23 When I used: as.Date(335,origin="1963-01-01"), for the first row, I got: [1] "1963-12-02" This is the format I want, though it is not yet complete. Time is missing. Again, I can't be doing this one after the other. I guess you have a better way of handling this. I have spent some time trying to get it right but I am really stuck. I would be most glad if you could spare your busy time to help me again. Thank you very much for your usual kind assistance. Best regards Ogbos __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.