Re: [R] write function to convert to date or delete
Hello, Maybe one possiblity is to search complete cases, such as complete.cases(z), and subset according to the output. It might also be interesting to check why you sometimes get NA. Regards, Pascal On 27 February 2014 16:11, Bill wrote: > Yes! that worked. > By the way, still puzzled about how to write the function that would delete > ones where there was an error in the function I used. Any idea on that? > > On Thu, Feb 27, 2014 at 8:06 PM, Pascal Oettli wrote: >> >> z <- strptime(radSampTrim$Captured.Time[1:30], "%F %T") > > > -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan __ R-help@r-project.org mailing list 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] write function to convert to date or delete
Yes! that worked. By the way, still puzzled about how to write the function that would delete ones where there was an error in the function I used. Any idea on that? On Thu, Feb 27, 2014 at 8:06 PM, Pascal Oettli wrote: > z <- strptime(radSampTrim$Captured.Time[1:30], "%F %T") > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] write function to convert to date or delete
Hello, I think this should be z <- strptime(radSampTrim$Captured.Time[1:30], "%F %T") Regards, Pascal On 27 February 2014 15:58, Bill wrote: > I just tried this: > > z <- strptime(radSampTrim$Captured.Time[1:30], "%d%b%Y") >> z[1:3] > [1] NA NA NA > > On Thu, Feb 27, 2014 at 7:39 PM, Pascal Oettli wrote: >> >> strptime > > > -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan __ R-help@r-project.org mailing list 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] find max value in different columns
Hello together, i have a data.frame like this one: IDONE TWO THREE 1 2 57 2 6 NA NA 3 5 7NA 4 1 NA NA Now i want a new column with the max-Value of "ONE", "TWO" and THREE. The result look like this one: IDONE TWO THREEMAX 1 2 57 7 2 6 NA NA 6 3 5 7NA 7 4 1 NA NA 1 how can i do this? thank you. Mat -- View this message in context: http://r.789695.n4.nabble.com/find-max-value-in-different-columns-tp4685905.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] write function to convert to date or delete
I just tried this: z <- strptime(radSampTrim$Captured.Time[1:30], "%d%b%Y") > z[1:3] [1] NA NA NA On Thu, Feb 27, 2014 at 7:39 PM, Pascal Oettli wrote: > strptime [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] write function to convert to date or delete
Hello, Did you tried the "strptime" function? Regards, Pascal On 27 February 2014 15:24, Bill wrote: > Hi. Thanks. Actually I don't know which ones are causing problems. I cannot > search through it because it is quite large (15 million records) > > > On Thu, Feb 27, 2014 at 7:22 PM, Pascal Oettli wrote: >> >> Hello, >> >> Could you provide an example of unproperly formatted entry? >> >> Regards, >> Pascal >> >> >> On 27 February 2014 15:03, Bill wrote: >> > I have a dataframe that looks like the below. I want to convert the >> > Captured.Time field to a date object. but some of the entries are not >> > properly formated and I get a message saying >> > Error in as.POSIXlt.character(as.character(x), ...) : >> > character string is not in a standard unambiguous format. >> > >> > So I want to write a function that will convert or delete. I could not >> > figure out how to do that and so I tried to write a function that would >> > convert or replace with text like noDateHere but that did not work >> > either. >> > Can anyone tell me how to accomplish this? >> > Here is what I tried: >> > >> > >> > convertOrOmit=function(dt){tryCatch(as.POSIXct(dt),error=print("noDateHere"))} >> > >> > X Captured.Time Latitude Longitude Value Unit Location.Name >> > 1 12696963 2012-08-07 11:00:51 39.16094 140.488345 cpm >> > 2 2056198 2013-11-10 03:14:19 32.84428 -117.224047 cpm >> > 3 727957 2014-01-28 04:47:54 35.80605 139.378928 cpm >> > 4 2864220 2013-10-22 19:41:53 35.07816 -106.612350 cpm >> > 5 5787688 2013-06-13 04:13:57 35.83174 136.202735 cpm >> > 6 6191345 2013-05-28 06:48:34 34.78944 137.949632 cpm >> > Device.ID MD5Sum Height Surface Radiation >> > 1NA b0465019b46289b82450c39ce1397b98 NANA >> > 2NA 8fa14a1227d23e6cf286785e8843cc39 NANA >> > 3NA c72cd7f9cedd59cf6e6892049dfbf9a0 NANA >> > 4NA aca82e39ff9098e45eea04f661f68dc7 NANA >> > 5NA cc9394e6dceb91f0e0de97cc2db57e19 NANA >> > 6NA f18d194a41e1448c7776dbeba8b351af NANA >> >Uploaded.Time Loader.ID >> > 1 2012-08-13 19:16:10.18555 10832 >> > 2 2013-12-05 01:47:24.154971 13958 >> > 3 2014-01-29 22:55:39.138043 14451 >> > 4 2013-10-26 13:50:17.629869 13743 >> > 5 2013-06-16 16:17:21.148239 12930 >> > 6 2013-06-04 23:31:55.455323 12841 >> > >> > [[alternative HTML version deleted]] >> > >> > __ >> > R-help@r-project.org mailing list >> > 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. >> >> >> >> -- >> Pascal Oettli >> Project Scientist >> JAMSTEC >> Yokohama, Japan > > -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan __ R-help@r-project.org mailing list 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] problem of calculate mean value of large time series data
If all you want is the mean, why not do it in Java? That sounds like a half gigabyte of memory in the best case, and you are trying to move it around from process to process, making copies here and there. If you are on 32 bit OS then that will fragment your memory pretty quick. Anyway, you should read the Posting Guide... HTML email should be plain text, no reproducible example, no sessionInfo... plenty of "opportunities for excellence" here. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 26, 2014 10:06:18 PM PST, cyl123 <505186...@qq.com> wrote: >Hi, > > >I have 20,000 time series variants whose length is about 3000 , and i >need to calculate the mean value of each variant. I invoke R with a >java client named RCaller, and I assigned the values of these time >series variants using RCaller. > > >The problem is : After I start running, the java program hangs. > > >The program seems ok with small size of data. > > >Could anyone help me with this? > > >Thanks > > >Hellen > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list >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 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] write function to convert to date or delete
Hi. Thanks. Actually I don't know which ones are causing problems. I cannot search through it because it is quite large (15 million records) On Thu, Feb 27, 2014 at 7:22 PM, Pascal Oettli wrote: > Hello, > > Could you provide an example of unproperly formatted entry? > > Regards, > Pascal > > > On 27 February 2014 15:03, Bill wrote: > > I have a dataframe that looks like the below. I want to convert the > > Captured.Time field to a date object. but some of the entries are not > > properly formated and I get a message saying > > Error in as.POSIXlt.character(as.character(x), ...) : > > character string is not in a standard unambiguous format. > > > > So I want to write a function that will convert or delete. I could not > > figure out how to do that and so I tried to write a function that would > > convert or replace with text like noDateHere but that did not work > either. > > Can anyone tell me how to accomplish this? > > Here is what I tried: > > > > > convertOrOmit=function(dt){tryCatch(as.POSIXct(dt),error=print("noDateHere"))} > > > > X Captured.Time Latitude Longitude Value Unit Location.Name > > 1 12696963 2012-08-07 11:00:51 39.16094 140.488345 cpm > > 2 2056198 2013-11-10 03:14:19 32.84428 -117.224047 cpm > > 3 727957 2014-01-28 04:47:54 35.80605 139.378928 cpm > > 4 2864220 2013-10-22 19:41:53 35.07816 -106.612350 cpm > > 5 5787688 2013-06-13 04:13:57 35.83174 136.202735 cpm > > 6 6191345 2013-05-28 06:48:34 34.78944 137.949632 cpm > > Device.ID MD5Sum Height Surface Radiation > > 1NA b0465019b46289b82450c39ce1397b98 NANA > > 2NA 8fa14a1227d23e6cf286785e8843cc39 NANA > > 3NA c72cd7f9cedd59cf6e6892049dfbf9a0 NANA > > 4NA aca82e39ff9098e45eea04f661f68dc7 NANA > > 5NA cc9394e6dceb91f0e0de97cc2db57e19 NANA > > 6NA f18d194a41e1448c7776dbeba8b351af NANA > >Uploaded.Time Loader.ID > > 1 2012-08-13 19:16:10.18555 10832 > > 2 2013-12-05 01:47:24.154971 13958 > > 3 2014-01-29 22:55:39.138043 14451 > > 4 2013-10-26 13:50:17.629869 13743 > > 5 2013-06-16 16:17:21.148239 12930 > > 6 2013-06-04 23:31:55.455323 12841 > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > 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. > > > > -- > Pascal Oettli > Project Scientist > JAMSTEC > Yokohama, Japan > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] write function to convert to date or delete
Hello, Could you provide an example of unproperly formatted entry? Regards, Pascal On 27 February 2014 15:03, Bill wrote: > I have a dataframe that looks like the below. I want to convert the > Captured.Time field to a date object. but some of the entries are not > properly formated and I get a message saying > Error in as.POSIXlt.character(as.character(x), ...) : > character string is not in a standard unambiguous format. > > So I want to write a function that will convert or delete. I could not > figure out how to do that and so I tried to write a function that would > convert or replace with text like noDateHere but that did not work either. > Can anyone tell me how to accomplish this? > Here is what I tried: > > convertOrOmit=function(dt){tryCatch(as.POSIXct(dt),error=print("noDateHere"))} > > X Captured.Time Latitude Longitude Value Unit Location.Name > 1 12696963 2012-08-07 11:00:51 39.16094 140.488345 cpm > 2 2056198 2013-11-10 03:14:19 32.84428 -117.224047 cpm > 3 727957 2014-01-28 04:47:54 35.80605 139.378928 cpm > 4 2864220 2013-10-22 19:41:53 35.07816 -106.612350 cpm > 5 5787688 2013-06-13 04:13:57 35.83174 136.202735 cpm > 6 6191345 2013-05-28 06:48:34 34.78944 137.949632 cpm > Device.ID MD5Sum Height Surface Radiation > 1NA b0465019b46289b82450c39ce1397b98 NANA > 2NA 8fa14a1227d23e6cf286785e8843cc39 NANA > 3NA c72cd7f9cedd59cf6e6892049dfbf9a0 NANA > 4NA aca82e39ff9098e45eea04f661f68dc7 NANA > 5NA cc9394e6dceb91f0e0de97cc2db57e19 NANA > 6NA f18d194a41e1448c7776dbeba8b351af NANA >Uploaded.Time Loader.ID > 1 2012-08-13 19:16:10.18555 10832 > 2 2013-12-05 01:47:24.154971 13958 > 3 2014-01-29 22:55:39.138043 14451 > 4 2013-10-26 13:50:17.629869 13743 > 5 2013-06-16 16:17:21.148239 12930 > 6 2013-06-04 23:31:55.455323 12841 > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > 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. -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan __ R-help@r-project.org mailing list 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] problem of calculate mean value of large time series data
Hi, I have 20,000 time series variants whose length is about 3000 , and i need to calculate the mean value of each variant. I invoke R with a java client named RCaller, and I assigned the values of these time series variants using RCaller. The problem is : After I start running, the java program hangs. The program seems ok with small size of data. Could anyone help me with this? Thanks Hellen [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] write function to convert to date or delete
I have a dataframe that looks like the below. I want to convert the Captured.Time field to a date object. but some of the entries are not properly formated and I get a message saying Error in as.POSIXlt.character(as.character(x), ...) : character string is not in a standard unambiguous format. So I want to write a function that will convert or delete. I could not figure out how to do that and so I tried to write a function that would convert or replace with text like noDateHere but that did not work either. Can anyone tell me how to accomplish this? Here is what I tried: convertOrOmit=function(dt){tryCatch(as.POSIXct(dt),error=print("noDateHere"))} X Captured.Time Latitude Longitude Value Unit Location.Name 1 12696963 2012-08-07 11:00:51 39.16094 140.488345 cpm 2 2056198 2013-11-10 03:14:19 32.84428 -117.224047 cpm 3 727957 2014-01-28 04:47:54 35.80605 139.378928 cpm 4 2864220 2013-10-22 19:41:53 35.07816 -106.612350 cpm 5 5787688 2013-06-13 04:13:57 35.83174 136.202735 cpm 6 6191345 2013-05-28 06:48:34 34.78944 137.949632 cpm Device.ID MD5Sum Height Surface Radiation 1NA b0465019b46289b82450c39ce1397b98 NANA 2NA 8fa14a1227d23e6cf286785e8843cc39 NANA 3NA c72cd7f9cedd59cf6e6892049dfbf9a0 NANA 4NA aca82e39ff9098e45eea04f661f68dc7 NANA 5NA cc9394e6dceb91f0e0de97cc2db57e19 NANA 6NA f18d194a41e1448c7776dbeba8b351af NANA Uploaded.Time Loader.ID 1 2012-08-13 19:16:10.18555 10832 2 2013-12-05 01:47:24.154971 13958 3 2014-01-29 22:55:39.138043 14451 4 2013-10-26 13:50:17.629869 13743 5 2013-06-16 16:17:21.148239 12930 6 2013-06-04 23:31:55.455323 12841 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Fwd: Fitting glm with maxit=0?
Here is another one. Thanks all again for the help! -- Forwarded message -- From: Xiaogang Su Date: Wed, Feb 26, 2014 at 9:38 AM Subject: Re: [R] Fitting glm with maxit=0? To: Thomas Lumley Thanks much Prof. Lumley for the tip. That'll be great. Yeah, occasionally the (minus) Hessian matrix may not be even invertible. I will certainly check by first computing it with the standard formula and comparing. = Xiaogang Su, Ph.D. Associate Professor Department of Mathematical Sciences University of Texas at El Paso 500 W. University Ave. El Paso, Texas 79968-0514 x...@utep.edu xiaogan...@gmail.com https://sites.google.com/site/xgsu00/ On Wed, Feb 26, 2014 at 9:22 AM, Thomas Lumley wrote: > On Wed, Feb 26, 2014 at 2:24 AM, Xiaogang Su wrote: > >> Dear All, >> >> Does anyone know if there is any way to obtain the variance-covariance >> matrix for any arbitrarily given estimates with the glm() function? >> > > Use maxit=1. The variance-covariance matrix is computed from the old > values, not the new values. > > You do need to check that the variance-covariance estimate is what you > want, since it's not designed for this use. Canonical link models with no > dispersion parameter should be ok, though. > >-thomas > > > -- > Thomas Lumley > Professor of Biostatistics > University of Auckland > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Fwd: Fitting glm with maxit=0?
Sorry that I forgot to include R Help in the addressee list. Here is one of my earlier follow-up emails. -- Forwarded message -- From: Xiaogang Su Date: Wed, Feb 26, 2014 at 8:48 AM Subject: Re: [R] Fitting glm with maxit=0? To: Prof Brian Ripley Thanks Prof. Ripley for the reply. Certainly, the theorem is for MLE. But MLE is not the only best asyptotical normal estimator. In particular, i am interested in a class of estimators that are close to MLE in an order smaller than 1/sqrt(n). By Slutsky theorem, they also follow the same asymptotic normal dist as MLE. In computing the information matrix, one could use the estimate itself instead of plugging in MLE. Anyhow, i think it would be a good feature to have with glm. One last note, forcing at least one more iteration, as in the current version of glm, is not wrong as that essentially gives a one step estimator. = Xiaogang Su, Ph.D. Associate Professor Department of Mathematical Sciences University of Texas at El Paso 500 W. University Ave. El Paso, Texas 79968-0514 x...@utep.edu xiaogan...@gmail.com https://sites.google.com/site/xgsu00/ On Feb 26, 2014 1:36 AM, "Prof Brian Ripley" wrote: > The theory used assumes that the estimates are MLEs (of the linear > predictor). > > One could say that > > the variance-covariance matrix for any arbitrarily given estimates > > is zero: there is no variability. > > On 26/02/2014 08:24, Xiaogang Su wrote: > >> Dear All, >> >> Does anyone know if there is any way to obtain the variance-covariance >> matrix for any arbitrarily given estimates with the glm() function? >> >> Here is what I really want. Given an arbitrary estimate (i.e., as starting >> points with the start= argument), the glm() function could return the >> corresponding variance-covariance matrix (or Hessian) and other quantities >> with no Netwon-Raphson iteration? This could have been done by setting >> maxit=0, but very unfortunately that is not an option in glm.control(). To >> illustrate the problem, >> >> mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv";) >> beta0 <- 1:3 >> control0 <- glm.control(epsilon = 1e10, maxit = 0, trace = FALSE) >> fit <- glm(admit ~ gre + gpa, data = mydata, family = "binomial", >> start=beta0, control=control0) >> summary(fit)$"cov.scaled" >> >> By the way, I am aware that I could directly compute the covariance matrix >> using the formula. I also know that I could extract the corresponding >> deviance by using the offset option. >> >> Any suggestion is greatly appreicated. >> >> Thanks, >> Xiaogang Su >> >> = >> Xiaogang Su, Ph.D. >> Associate Professor >> Department of Mathematical Sciences >> University of Texas at El Paso >> 500 W. University Ave. >> El Paso, Texas 79968-0514 >> x...@utep.edu >> xiaogan...@gmail.com >> https://sites.google.com/site/xgsu00/ >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> 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. >> >> > > -- > Brian D. Ripley, rip...@stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UKFax: +44 1865 272595 > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] [SPAM?] R Progress Bar
Sorry, I have never used these functions before. There is the msgWindow function, but it works on a graphic device number, and may not work on the external pointer object that winProgressBar returns. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 26, 2014 5:18:57 PM PST, lslo...@sjm.com wrote: >Hi Jeff >Indeed it appears to be affected by the Revolution R IDE as it runs >fine in R GUI. What I am really looking for is a function that I can >call that modifies or creates the progress bar window properties so >that the progress bar is 'Always on Top.' I am really unfamiliar with >Tclk, so I wonder if it may have something like that. > >_ >Sent from http://r.789695.n4.nabble.com __ R-help@r-project.org mailing list 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] additions to r pivot table
Hi Burnette, Try: indx <- grep("\\bMW\\b|\\bOT\\b|\\bposter\\b|\\brecords\\b", rownames(res3)) indx1 <- grep("Grand Total",rownames(res3)) res3R <- as.data.frame(matrix(NA,ncol=ncol(res3),nrow=nrow(res3),dimnames= list(rownames(res3),c("rate of Count of Case ID", "rate of Sum of BW_Due", "rate of Sum of BW_ATP", "rate of Sum of EEs_Rep" res3R[c(indx,indx1),] <- t(t(res3[c(indx,indx1),])/unlist(res3[indx1,])) indx2 <- as.vector(table(gsub("\\_.*","",rownames(res3[-c(indx,indx1),] #or #indx2 <- res3[indx,1] res3R[-c(indx,indx1),] <- res3[-c(indx,indx1),]/unlist(res3[rep(indx,indx2),]) res4 <- cbind(res3,res3R)[,rep(seq(1,8,by=4),4) + rep(seq(0,3),each=2)] head(res4,2) # Count of Case ID rate of Count of Case ID Sum of BW_Due #MW 2 0.4 168.11 #MW_tip 1 0.5 55.76 # rate of Sum of BW_Due Sum of BW_ATP rate of Sum of BW_ATP Sum of EEs_Rep #MW 0.7202348 155.86 0.7953664 29 #MW_tip 0.3316876 55.76 0.3577570 9 # rate of Sum of EEs_Rep #MW 0.5370370 #MW_tip 0.3103448 A.K. On Wednesday, February 26, 2014 12:57 PM, "Crombie, Burnette N" wrote: A.K., I’m struggling with adding columns that calculate rate in the dataset you helped me with earlier: Is this something I should resubmit to Rhelp as a new question? Thanks! FLSAdata <- data.frame(CaseID = c(1881, 1882, 1883, 1884, 1885), ViolationDesc = c("records", "poster", "MW", "OT", "MW"), ReasonDesc = c("", "", "tip", "bonus", "uniform"), BW_Due = c(0, 0, 55.76, 65.30, 112.35), BW_ATP = c(0, 0, 55.76, 40.10, 100.10), EEs_Rep = c(4, 11, 9, 10, 20)) FLSAdata$CaseID <- factor(FLSAdata$CaseID) FLSAdata [FLSAdata ==""] <- NA library(reshape2) FLSAdata_melt <- melt(FLSAdata,id=c("CaseID", "ViolationDesc", "ReasonDesc"),measure=c("BW_Due", "BW_ATP", "EEs_Rep"), na.rm=FALSE) res1 <- acast(FLSAdata_melt, ViolationDesc + ReasonDesc ~ variable, sum, margins=TRUE)[,-4] res2 <- within(as.data.frame(res1),`Count of Case ID` <- dcast(FLSAdata_melt, ViolationDesc + ReasonDesc ~ variable, length, margins=TRUE)[,3])[,c(4,1:3)] colnames(res2)[2:4] <- paste("Sum of",colnames(res2)[2:4]) rownames(res2)[length(rownames(res2))] <- "Grand Total" indx <- grepl("all",rownames(res2)) ord1 <- unlist(tapply(seq_len(nrow(res2)),list(cumsum(c(TRUE,diff(indx)<0))),FUN=function(x) c(tail(x,1),head(x,-1)) ),use.names=FALSE) res3 <- res2[ord1,] rownames(res3) <- gsub("\\_\\(all\\)","",rownames(res3)) res3 Burnette Crombie Construction Industry Research & Policy Center (CIRPC) 219 Stokely Management Center The University of Tennessee, Knoxville 37996 ph 865.974.4422 fax 865.545.4193 http://cirpc.bus.utk.edu __ R-help@r-project.org mailing list 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] R Progress Bar
I ran the example code in the winProgressBar help file and it ran in normal display mode (not minimized). Have you run your code in RGui? Those other tools may be affecting winProgressBar. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 26, 2014 9:24:35 AM PST, slomanl1 wrote: >I am running Windows 7 64bit. Running a script on Revolution R or R >Studio >(the behavior is the same.) The sample script reproduces the problem: > >pb <- winProgressBar("test progress bar", "Some information in %", > 0, 100, 50) >Sys.sleep(0.5) >u <- c(0, sort(runif(20, 0, 100)), 100) >for(i in u) { >Sys.sleep(0.1) >info <- sprintf("%d%% done", round(i)) >setWinProgressBar(pb, i, sprintf("test (%s)", info), info) >} >Sys.sleep(5) >close(pb) > >Also, tkProgressBar() behaves the same. > > > >-- >View this message in context: >http://r.789695.n4.nabble.com/R-Progress-Bar-tp4685847p4685875.html >Sent from the R help mailing list archive at Nabble.com. > >__ >R-help@r-project.org mailing list >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 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] Fitting glm with maxit=0?
Thanks David for stopping by this thread. I have to admit that the word "arbitrary" was arbitrarily chosen. As I explained in the second email in the thread, what I am really interested are some estimates obtained via other methods that have the same asymptotic distribution as MLE. The following simple example verifies what Thomas indicated: the vcov matrix after one iteration is based on the original starting values, rather than the one-step renewed values: mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv";) fit1 <- glm(admit ~ gre + gpa, data = mydata, family = "binomial") set.seed(669) beta0 <- jitter(coef(fit1)); beta0 control0 <- glm.control(epsilon=1e20, maxit=1, trace=F) fit <- glm(admit ~ gre + gpa, data = mydata, family = "binomial", start=beta0, control=control0) cbind(beta0, one.step= fit$coef) V0 <- summary(fit)$"cov.scaled"; V0 X <- as.matrix(cbind(1, mydata$gre, mydata$gpa)); eta <- as.vector(X%*%beta0) expit <- function(x) (tanh(x/2)+1)/2 p <- expit(eta) W <- diag(p*(1-p)) V0 <- solve(t(X)%*%W%*%X); V0 As you can see, the two V0s are identical, although sometimes they may be different sheerly because of floating point rounding errors. I could have obtained the variance-covariance matrix or Hessian using the known results for each other type of GLMs. But thought using glm() function could make the codes more generic. And it is working now. = Xiaogang Su, Ph.D. Associate Professor Department of Mathematical Sciences University of Texas at El Paso 500 W. University Ave. El Paso, Texas 79968-0514 x...@utep.edu xiaogan...@gmail.com https://sites.google.com/site/xgsu00/ On Wed, Feb 26, 2014 at 3:55 PM, David Winsemius wrote: > > On Feb 26, 2014, at 12:24 AM, Xiaogang Su wrote: > > > Dear All, > > > > Does anyone know if there is any way to obtain the variance-covariance > > matrix for any arbitrarily given estimates with the glm() function? > > > > Here is what I really want. Given an arbitrary estimate (i.e., as > starting > > points with the start= argument), the glm() function could return the > > corresponding variance-covariance matrix (or Hessian) and other > quantities > > with no Netwon-Raphson iteration? > > Not with an arbitrary start argument. You have offered a counter-example. > > > This could have been done by setting > > maxit=0, but very unfortunately that is not an option in glm.control(). > To > > illustrate the problem, > > > > mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv";) > > beta0 <- 1:3 > > control0 <- glm.control(epsilon = 1e10, maxit = 0, trace = FALSE) > > I admit to curiosity regarding how you interpreted the error message this > generates: > > Error in glm.control(epsilon = 1e+10, maxit = 0, trace = FALSE) : > maximum number of iterations must be > 0 > > If you fix that problem you will be faced with another one induced by your > unrealistic starting values. > > -- > David. > > > fit <- glm(admit ~ gre + gpa, data = mydata, family = "binomial", > > start=beta0, control=control0) > > summary(fit)$"cov.scaled" > > > > By the way, I am aware that I could directly compute the covariance > matrix > > using the formula. I also know that I could extract the corresponding > > deviance by using the offset option. > > > > Any suggestion is greatly appreicated. > > > > Thanks, > > Xiaogang Su > > > > = > > > > > > [[alternative HTML version deleted]] > > > > __ > > R-help@r-project.org mailing list > > 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. > > David Winsemius > Alameda, CA, USA > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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 assign membership after hierachical clustering(agnes{cluster})
Did you look at the help for agnes.object as directed by the help file that you yourself linked in your email? If none of those components meet your needs, as.hclust() - also pointed to by the agnes.object helpfile - might give you what you want. Sarah On Wed, Feb 26, 2014 at 3:08 PM, Tianchen Wu wrote: > Dear list, > > My Problem Setting Looks as Follows: > > I have a list of object [O1,O2,O3,O4,..O6000], on which a pairwise > distance matrix is defined, called dist.matrix. > > After that, a agnes has been conducted on the distance matrix. > > agn1<-agnes(dist.matrix,method="ward") > > even cutted > > agn1_cut<-cut(agn1,h=9000) #something like this > > Now how can I get back the cluster membership? > > Another difficulty here is , is that possible that I can get back the > cluster preserved in the order of original list of object.(my dist.matrix > is showhow still order preserved) > > > > By the way, for a reproductive sample code, I will point to > > Examples in > http://stat.ethz.ch/R-manual/R-patched/library/cluster/html/agnes.html > > How to get cluster label for agn1, for instance > > > > > I have been googled for 2 hours. I am wondering why no one has question > like that before > thank you very much. > > -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list 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 assign membership after hierachical clustering(agnes{cluster})
Dear list, My Problem Setting Looks as Follows: I have a list of object [O1,O2,O3,O4,..O6000], on which a pairwise distance matrix is defined, called dist.matrix. After that, a agnes has been conducted on the distance matrix. agn1<-agnes(dist.matrix,method="ward") even cutted agn1_cut<-cut(agn1,h=9000) #something like this Now how can I get back the cluster membership? Another difficulty here is , is that possible that I can get back the cluster preserved in the order of original list of object.(my dist.matrix is showhow still order preserved) By the way, for a reproductive sample code, I will point to Examples in http://stat.ethz.ch/R-manual/R-patched/library/cluster/html/agnes.html How to get cluster label for agn1, for instance I have been googled for 2 hours. I am wondering why no one has question like that before thank you very much. ## [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Fitting glm with maxit=0?
On Feb 26, 2014, at 12:24 AM, Xiaogang Su wrote: > Dear All, > > Does anyone know if there is any way to obtain the variance-covariance > matrix for any arbitrarily given estimates with the glm() function? > > Here is what I really want. Given an arbitrary estimate (i.e., as starting > points with the start= argument), the glm() function could return the > corresponding variance-covariance matrix (or Hessian) and other quantities > with no Netwon-Raphson iteration? Not with an arbitrary start argument. You have offered a counter-example. > This could have been done by setting > maxit=0, but very unfortunately that is not an option in glm.control(). To > illustrate the problem, > > mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv";) > beta0 <- 1:3 > control0 <- glm.control(epsilon = 1e10, maxit = 0, trace = FALSE) I admit to curiosity regarding how you interpreted the error message this generates: Error in glm.control(epsilon = 1e+10, maxit = 0, trace = FALSE) : maximum number of iterations must be > 0 If you fix that problem you will be faced with another one induced by your unrealistic starting values. -- David. > fit <- glm(admit ~ gre + gpa, data = mydata, family = "binomial", > start=beta0, control=control0) > summary(fit)$"cov.scaled" > > By the way, I am aware that I could directly compute the covariance matrix > using the formula. I also know that I could extract the corresponding > deviance by using the offset option. > > Any suggestion is greatly appreicated. > > Thanks, > Xiaogang Su > > = > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > 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. David Winsemius Alameda, CA, USA __ R-help@r-project.org mailing list 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] plot out the predicted values and the upper and lower limits
When in doubt, first consult the included online help. ?predict.lm Offers this example, which seems to meet the request x <- rnorm(15) y <- x + rnorm(15) predict(lm(y ~ x)) new <- data.frame(x = seq(-3, 3, 0.5)) predict(lm(y ~ x), new, se.fit = TRUE) pred.w.plim <- predict(lm(y ~ x), new, interval = "prediction") pred.w.clim <- predict(lm(y ~ x), new, interval = "confidence") matplot(new$x, cbind(pred.w.clim, pred.w.plim[,-1]), lty = c(1,2,2,3,3), type = "l", ylab = "predicted y") (note that all the functions come with R and are loaded by default) And predict.lm can be found in the "See also" section of ?predict. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/25/14 2:57 PM, "varin sacha" wrote: >Hi, >I have realized a multiple linear regression. >To know how well my model does in terms of prediction, I can compute >prediction intervals bands and decide if they are narrow enough to be of >use. If they are too wide, then they probably are not useful. > >So what I am trying to do is : >Theoretically I know that I can use the "predict" command in R to >generate the prediction interval for a set of points. The idea is to find >the linear regression using the lm command. Then I can use the predict >command to get the prediction interval for a set of points in the domain. >Then I plot out the predicted values as well as the upper and lower >limits of the prediction intervals for those values. >My problem is to practice what I theoretically know, especially using R. > >My linear model is the following : >LinearModel.1 <- lm(GDP.per.head ~ Competitivness.score + Quality.score, >data=Dataset) >summary(LinearModel.1) >predict(LinearModel.1, se.fit = FALSE, scale = NULL, df = Inf,interval = >c("none", "confidence", "prediction"),level = 0.95, type = c("response", >"terms"),terms = NULL) > >Could you please help me with my R codes ? > >Thanks for your precious help, > [[alternative HTML version deleted]] > __ R-help@r-project.org mailing list 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] plot out the predicted values and the upper and lower limits
On 27/02/14 05:43, varin sacha wrote: Many thanks Rolf, These codes below are ok : LinearModel.1 <- lm(GDP.per.head ~ Competitivness.score + Quality.score, data=Dataset) summary(LinearModel.1) predict(LinearModel.1, se.fit = FALSE, scale = NULL, df = Inf,interval = c("prediction"),level = 0.95, type = c("response")) One problem remains : If I want to plot out (in a same graph) the predicted values as well as the upper and lower limits of the prediction intervals for those values. How can I do, many thanks once more. This is very a very basic R plotting problem. If you are going to use R, you should learn how to use R. Your emails indicate that you haven't really got a clue. Read some of the excellent introductory material available from the R web page. Start with a thorough read of "An Introduction to R". Then have a look at some of the material available under "contributed documentation". It will take a while but will be worth the effort if you wish to become anything like competent at using R. I could tell you how to do the plot you want, in a few lines, but I am not going to. You need to do some learning. cheers, Rolf P. S. An indication that you haven't a clue is the fact that you use interval = c("prediction") Just what on earth do you think that "c()" is doing for you here? Learn what the c() function means and what its purpose is. Don't just slap down bits of code in a higgledy-piggledy manner and hope that something will work. Wrapping "prediction" in c() is harmless in this instance, but is unnecessary, redundant and confusing. In general using inappropriate code that you don't understand will result in errors. R. __ R-help@r-project.org mailing list 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] longitude, latitude, heat map
Well, ?image and ?heatmap (! what else?) can do this -- except that you probably want this on some sort of map projection, right? Assuming that's the case, check the "spatial" task view on CRAN and/or post on the r-sig-geo list . I am sure there are many packages that can do various flavors of this. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch On Wed, Feb 26, 2014 at 12:56 PM, Bill wrote: > Hi. Does anyone know of a package that can take the three attributes, > longitude, latitude, and heatvalue and generate a heat map? > > Thank you. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > 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 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] longitude, latitude, heat map
Hi. Does anyone know of a package that can take the three attributes, longitude, latitude, and heatvalue and generate a heat map? Thank you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Plots with Y axis split into two scales
Imagine you were plotting two sets, (x1, y1) and (x2, y2) on the same plot, where x1 and x2 have the same range, but y1 and y2 need different axis scales. Here's an example that I think illustrates the idea. It's a long way from being general, and if I were making it into a function in a package, I would certainly find ways to parameterize the various y ranges. But I think it illustrates a way to accomplish what was requested. ## some fake data x <- 1:4 y <- c(1,105, 2, 130) is.lo <- y < 100 x1 <- x[is.lo] y1 <- y[is.lo] x2 <- x[!is.lo] y2 <- y[!is.lo] yl1 <- c(0,10) yl2 <- c(50,140) ya1 <- c(0,5) ya2 <- c(100,140) par(mar=c(5.1, 4.1, 4.1, 4.1)) plot(range(x), yl1, type='n', yaxt='n', ylab='', xlab='X') mtext('Low range of Y', side=2, line=2.5, adj=0.25) points(x1,y1) axis(2, pretty(ya1)) par(new=TRUE)## this is the key "trick" ## I can now add data to the existing plot, ## using any data ranges I want plot(range(x), yl2, type='n', yaxt='n', xaxt='n', ylab='', xlab='') points(x2,y2, col='red') axis(4, pretty(ya2)) mtext('High range of Y', side=4, line=2.5, adj=0.75) One can build exactly what one wants using base R graphics tools. (And I decline to address questions of whether such a plot is a good way to present data) -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/25/14 9:18 AM, "David Parkhurst" wrote: >I have a "Y" variable with many values less than 50, and many fewer >between 50 and 250.I'd like to plot those Y's against an X, with two >scales on the Y axis---maybe 60% of the axis height for 0-50 and the top >40% for 50-250.(I can't use log(Y) because there are many zeroes, and >that is the most desirable value.) > >I think I've seen plots done that way, but is there a way to create them >in R? > >Thanks for any help. > > > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list >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 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] Discrepant lm() and survreg() standard errors with weighted fits
I understand that the robust variances may lead to a different standard error. I want the standard error valid for heteroscedastic data, ultimately, because I have very good estimates of the measurement variances (why I'm doing weighted fits in the first place). For the simple example here, the White estimate is somewhere between the standard error for lm() and survreg(): > library(sandwich) > test <- data.frame(x=1:6, y=c(1,3,2,4,6,5)) > vcovHC(lm(y~x, data=test), type=c('HC')) (Intercept) x (Intercept) 0.34636190 -0.08372245 x -0.08372245 0.02811895 > vcovHC(lm(y~x, data=test), type=c('HC'))[1,1]^0.5 [1] 0.5885252 > vcovHC(lm(y~x, data=test), type=c('HC'))[2,2]^0.5 [1] 0.1676871 (The HC3 method gives SEs which are consistent with those from lm().) I don't understand how survreg() can do better than White? Thanks again for your help, Kyle On Wed, Feb 26, 2014 at 7:21 AM, Therneau, Terry M., Ph.D. wrote: > The robust variances are a completely different estimate of standard error. > For linear models the robust variance has been rediscovered many times and > so has lots of names: the White estimate in economics, the Horvitz-Thompson > in surveys, working independence esitmate in GEE models, infinitesimal > jackknife in stat literature, But it is not the MLE estimate. > When the robust estimate was added to survreg (and coxph) I made the > decision that IF someone was invoking the robust variance, AND they were > using weights, that simple case weights were unlikely to be what they had. > So I chose to make treat the weights as sampling or precision weights, in > contraindication to the longer standing behavior of coxph/survreg without a > robust argument. Looking back, I probably should have taken one step > further and changed the routines' behavior globally on the presumption that > true case weights are vanishingly rare. They were not uncommon in my > computing youth, when computer memory of < 64KB was usual (max possible on > the PDP-11 architecture). But one is always cautious about non-backwards > compatable changes. > > begin included message - > > > When I use robust=T, I do not understand how survreg treats the > weights as sampling weights and arrives at a different standard error > from lm: > >> summary(survreg(Surv(y)~x, dist='gaussian', data=test, weights=rep(2,6), >> robust=T))$table > > Value Std. Err (Naive SE)zp > (Intercept) 0.400 0.29426260 0.5219013 1.35933 1.740420e-01 > x0.8857143 0.08384353 0.1340119 10.56390 4.380958e-26 > Log(scale) -0.2321528 0.08117684 0.2041241 -2.85984 4.238543e-03 > __ R-help@r-project.org mailing list 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] R Progress Bar
I am running Windows 7 64bit. Running a script on Revolution R or R Studio (the behavior is the same.) The sample script reproduces the problem: pb <- winProgressBar("test progress bar", "Some information in %", 0, 100, 50) Sys.sleep(0.5) u <- c(0, sort(runif(20, 0, 100)), 100) for(i in u) { Sys.sleep(0.1) info <- sprintf("%d%% done", round(i)) setWinProgressBar(pb, i, sprintf("test (%s)", info), info) } Sys.sleep(5) close(pb) Also, tkProgressBar() behaves the same. -- View this message in context: http://r.789695.n4.nabble.com/R-Progress-Bar-tp4685847p4685875.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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 fit a sine curve to those data
Hello R-users, I am a biginner in R and I would like to fit a sinusoidal curve to my data. I couldn't get a nice results. here is an extract of my data: line time meters 1 1 04:273.1 2 2 10:480.9 3 3 16:492.9 4 4 23:001.0 5 5 05:033.1 6 6 11:291.0 7 7 17:262.8 8 8 23:421.1 9 9 05:423.0 10 10 12:141.1 11 11 18:092.7 12 12 00:311.2 the time is in hours. I have tried to run this scrip trying to fit my data by eye using a time every 6 hours (just to try with a fixed time) TimeD <- c(0,6,12,18,24) MetersD <- c(3.1,0.9,2.9,1,3.1) AverageHigh <- (max(MetersD) + mean(MetersD)) / 2 AverageLow <- (min(MetersD) + mean(MetersD)) / 2 A <- (AverageHigh - AverageLow) / 2 K <- (AverageHigh + AverageLow) / 2 period <- mean(TimeD[c(-1,-2,-length(TimeD)-1,-length(TimeD))]) f <- 2 * pi / period phi <- TimeD[2] + (pi / (2 * f)) Curve.plot <-(A * sin(f * (TimeD - phi))) + K could somebody suggest me a way?It is becoming very complicated to get out from here. Many thanks __ R-help@r-project.org mailing list 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] libPaths how to change (R 3.0.2 64bit, RStudio 0.98.501, Windows 7)
Thanks Jeff. What I actually ended up doing is closing down RStudio and deleting the other folder where I didn't want it to store and re-installing those packages from the deleted folders. So far so good. Dan -Original Message- From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] Sent: Wednesday, February 26, 2014 1:19 AM To: Lopez, Dan; R help (r-help@r-project.org) Subject: Re: [R] libPaths how to change (R 3.0.2 64bit, RStudio 0.98.501, Windows 7) What you are really asking is how environment variables get set outside of R, which is very OS-specific and not on topic here, and there can be numerous ways for it to happen even on a single OS. I will warn you that the path syntax can vary in Windows depending on where it gets set so beware of ~ expansion (doesn't always work) and forward/back-slash distinctions. You can start looking in the System control panel under Advanced and Environment Variables... you will probably need Admin privileges to go there. Google is your friend. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 25, 2014 10:57:00 AM PST, "Lopez, Dan" wrote: >R Experts, > >I had a problem when trying to install package tm. The install looked >successful ("Package 'tm' successfully unpacked and MD5 sums checked") >but I could not load it through library(tm). It kept complaining that >tm package was not installed. > >So it was through this problem that I realized I had two locations >where my packages are stored: >C:R/R-3.0.2/library #Preferred >lab.gov/users/lopez/Data/documents/R/win-library/3.0 #NOT >Preferred > >I am not sure when and how the second location was created. But now I >want to change my default location to the "Preferred" location. > >I referred to >http://stat.ethz.ch/R-manual/R-devel/library/base/html/libPaths.html >but I don't understand how to set the environment variables R_LIBS or >R_LIBS_SITE, which is what I understood I need to do. I looked in >R\R-3.0.2\etc and did not find a Renviron file (per >http://mathematicalcoffee.blogspot.com/2013/04/getting-rstudio-to-include-your.html). >So I created one (file name exactly as "Renviron") and set the variable >(R_LIBS_USER=~/R/library) there but when I do the following I still see >both library paths: > > .libPaths() >[1] "lab.gov/users/lopez/Data/documents/R/win-library/3.0" >"C:/R/R-3.0.2/library" > >I only want the preferred path. How do I remove the unwanted path? > >BTW I did find a solution to installing tm properly but want to prevent >similar problem from happening in the future by only having one library >path. > >Dan Lopez >Workforce Analyst >HRIM - Workforce Analytics & Metrics >Strategic Human Resources Management >(925) 422-0814 > > > > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list >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 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] Add primary key to sqlite table
Hello, is it possible to add a primary key to a sqlite table with Rsqlite? Without create a complex query string? I have tried dbWriteTable but don't found an option to define a field as primary key. Has someone suggestions? Thanks, Christian __ R-help@r-project.org mailing list 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] install packages from R-forge SVN
R-helpers: I was curious if anyone developed a package/approach to installing packages directly from the R-forge SVN subsystem (rather than waiting for it to build)? I can, of course, SVN it command line but I was hoping for an install.packages("svn://") sort of approach. Cheers! --j -- Jonathan A. Greenberg, PhD Assistant Professor Global Environmental Analysis and Remote Sensing (GEARS) Laboratory Department of Geography and Geographic Information Science University of Illinois at Urbana-Champaign 259 Computing Applications Building, MC-150 605 East Springfield Avenue Champaign, IL 61820-6371 Phone: 217-300-1924 http://www.geog.illinois.edu/~jgrn/ AIM: jgrn307, MSN: jgrn...@hotmail.com, Gchat: jgrn307, Skype: jgrn3007 __ R-help@r-project.org mailing list 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] R Progress Bar
This will probably depend greatly on which operating system you are using and which progress bar function(s) you are using, neither of which is clear from your message. If you tell us what your OS is (and possibly how you are running R, GUI, commandline, etc.) and show us some sample code including any packages loaded, then we will have a better chance at helping you. On Tue, Feb 25, 2014 at 5:37 PM, slomanl1 wrote: > When I run my script, the progress bar is always minimized, and I have to > manually click on it to be visible. Does anyone know how to put an R > progress bar on top once it is created? > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/R-Progress-Bar-tp4685847.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > 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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list 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] Plots with Y axis split into two scales
I nominate the following for the fortunes package. > . I still don't think it would be fair to the data, and you > don't want those data liberation people parading around your laboratory > with pictures of helpless data being devoured by a Babbage Difference > Engine. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list 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] plot out the predicted values and the upper and lower limits
Many thanks Rolf, These codes below are ok : LinearModel.1 <- lm(GDP.per.head ~ Competitivness.score + Quality.score, data=Dataset) summary(LinearModel.1) predict(LinearModel.1, se.fit = FALSE, scale = NULL, df = Inf,interval = c("prediction"),level = 0.95, type = c("response")) One problem remains : If I want to plot out (in a same graph) the predicted values as well as the upper and lower limits of the prediction intervals for those values. How can I do, many thanks once more. Best, Le Mercredi 26 février 2014 4h59, varin sacha a écrit : Hi, I have realized a multiple linear regression. To know how well my model does in terms of prediction, I can compute prediction intervals bands and decide if they are narrow enough to be of use. If they are too wide, then they probably are not useful. So what I am trying to do is : Theoretically I know that I can use the "predict" command in R to generate the prediction interval for a set of points. The idea is to find the linear regression using the lm command. Then I can use the predict command to get the prediction interval for a set of points in the domain. Then I plot out the predicted values as well as the upper and lower limits of the prediction intervals for those values. My problem is to practice what I theoretically know, especially using R. My linear model is the following : LinearModel.1 <- lm(GDP.per.head ~ Competitivness.score + Quality.score, data=Dataset) summary(LinearModel.1) predict(LinearModel.1, se.fit = FALSE, scale = NULL, df = Inf,interval = c("none", "confidence", "prediction"),level = 0.95, type = c("response", "terms"),terms = NULL) Could you please help me with my R codes ? Thanks for your precious help, [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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 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] png-generation from script (non-X11 env) now broken?
This is mostly a guess... At the end of January, your script succeeded. Your OS was "built Sun Feb 23 05:14:37 PST 2014." Your script failed on Feb 26. You probably had not made any changes to R between the end of January and Feb 26 (I don't see any mention of having done so, and R does not update itself -- unless you have some OS level package manager that does it for you; I wouldn't know about that). At this point, I'd wonder if the OS update on 2/23 changed come libraries that R relies on for png graphics. Perhaps you need to rebuild R, so that it uses the changed/updated OS libraries. Hopefully that OS update did not completely remove libraries that R depends on for png. -Don -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 2/25/14 10:36 AM, "David Wolfskill" wrote: >Since ... hmmm.. May 2012, I've had a cron-initiated script running >monthly to extract some data and generate some numeric tables and >plots (in PNG format). > >In its "normal" mode, the script automagically sends its results >to a small handful of managers on the first of each month. Out of >self-defense, I set up a "preview" run several days before the real >one; the preview doesn't go quite as high in the management chain. > >This morning, I found a message in my mailbox from such a preview run: > >| Error in .External2(C_X11, paste("png::", filename, sep = ""), g$width, > : >| unable to start device PNG >| Calls: gen_build_histogram -> png >| In addition: Warning message: >| In png(filename = fn, height = height, width = width, units = "in", : >| unable to open connection to X11 display '' >| Execution halted > >[This was running R-3.0.2_1 in FreeBSD/amd64 9.2-STABLE >r262323M/262357:902506, built Sun Feb 23 05:14:37 PST 2014.] > >I admit that I haven't been following changes in R very closely -- >the script had been running reliably for over a year, and it's not >one of the fires I've been fighting recently. > >But the implication -- that png() was suddenly[1] changed so that it >requires the ability to connect to an X11 display -- seemed peculiar >enough that I would have thought a quick search would lead me to soe >discussion of a change of this magnitude, rationale, and what folks >might do to mitigate the effects. > >Based on one message I found (from 02 Mar 2008!), I did take a look at >"help png" output, and saw the reference there to bitmap(). I tried ... >hacking ... my functions to use "bitmap(fn, ...)" instead of >"png(filename = fn, ...)", but that looks as if it's leading me astray: > >| Error in strwidth(legend, units = "user", cex = cex, font = text.font) >: >| family 'mono' not included in postscript() device >| Calls: gen_build_histogram -> legend -> strwidth >| Execution halted > > >So... what's someone who wants to use R to generate PNG-format files >from an environment that is bereft of X11 to do? > > >1: "Suddenly" because it *had* been working up to 01 Feb 2014, at least. > >[I'll be happy to sumamrize responses that aren't sent to the list.] > >Peace, >david >-- >David H. Wolfskill r...@catwhisker.org >Taliban: Evil cowards with guns afraid of truth from a 14-year old girl. > >See http://www.catwhisker.org/~david/publickey.gpg for my public key. __ R-help@r-project.org mailing list 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] R help table from HTML
Hi, Check the ?str() of my.table. library(XML) u='http://www.ininternet.org/calorie.htm' tables1 = readHTMLTable(u) my.table1=tables1[[9]] with(my.table1,mean(PROTEINE)) #[1] NA #Warning message: #In mean.default(PROTEINE) : # argument is not numeric or logical: returning NA str(my.table1) 'data.frame': 215 obs. of 6 variables: $ ALIMENTO : Factor w/ 215 levels "ACCIUGHE SALATE",..: 1 2 3 4 5 6 7 8 9 10 ... $ PROTEINE : Factor w/ 31 levels "0","1","10","11",..: 18 19 26 11 2 18 19 2 2 17 ... $ GRASSI : Factor w/ 42 levels "0","1","10","100",..: 2 6 1 15 1 2 6 1 1 20 ... $ CARBOIDRATI: Factor w/ 39 levels "0","1","10","100",..: 1 1 13 1 37 1 1 3 5 1 ... $ CALORIE : Factor w/ 100 levels "10","100","115",..: 3 25 2 36 47 3 25 76 70 4 ... $ COLESTEROLO: Factor w/ 34 levels "0.000","0.006",..: 19 25 1 19 1 17 25 1 1 25 ... my.table1[,-1] <- lapply(my.table1[,-1], function(x) as.numeric(as.character(x))) with(my.table1,mean(PROTEINE)) #[1] 10.81395 #or you could use `colClasses` argument in ?readHTMLTable tables = readHTMLTable(u,colClasses=c("character",rep("numeric",5))) my.table <- tables[[9]] with(my.table,mean(PROTEINE)) #[1] 10.81395 Also, it is not recommended to ?attach the dataset. Use ?with. Hope it helps. A.K. Hello, I have imported a html table into R: u='http://www.ininternet.org/calorie.htm' tables = readHTMLTable(u) my.table=tables[[9]] View(my.table) But now I have problems when I want to analyze the data and apply any function, for example > mean(PROTEINE) Warning message: In mean.default(PROTEINE) : argument is not numeric or logical: returning NA Please tell me how to import a table so that I could analyze the data properly. __ R-help@r-project.org mailing list 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] combine 2 data.frames in dependence of the ID
Hi Mat, Please check the str() of your dat2. If I change dat2$DATE <- as.POSIXlt(dat2$DATE) dcast(ddply(merge(dat1,dat2,by="FS_ID")[,-1],.(ABNR), mutate, DATE=seq_along(DATE)),ABNR~DATE,value.var="POST") #Error in attributes(out) <- attributes(col) : # 'names' attribute [9] must be the same length as the vector [3] A.K. On Wednesday, February 26, 2014 9:57 AM, Matthias Weber wrote: Thanks first for the help, Your description works with the example perfect. If I try it with my data, there is an error. error in attributes(out) <- attributes(col) : attribute 'names' [306] must have the same length, than the vector [1] My data.frame "dat2" has 306 lines, could be this the reason? What does R mean with the vector? Thanks a lot for the help. Best regards. Mat. -Ursprüngliche Nachricht- Von: arun [mailto:smartpink...@yahoo.com] Gesendet: Mittwoch, 26. Februar 2014 10:08 An: Matthias Weber Betreff: Re: [R] combine 2 data.frames in dependence of the ID #or you could do: dcast(ddply(merge(dat1,dat2,by="FS_ID")[,-1],.(ABNR), mutate, DATE=cut(seq_along(DATE),breaks=c(0,1,2,3,4,5,6,7,8,9),labels=c("FIRST","SECOND","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"))),ABNR~DATE,value.var="POST") # ABNR FIRST SECOND THREE #1 33688812 28 29 28.3 #2 3380 10 NA NA A.K. On Wednesday, February 26, 2014 3:58 AM, arun wrote: Try: library(plyr) library(reshape2) res <- dcast(ddply(merge(dat1,dat2,by="FS_ID")[,-1],.(ABNR), mutate, DATE=seq_along(DATE)),ABNR~DATE,value.var="POST") colnames(res)[-1] <- c("FIRST","SECOND","THREE") res # ABNR FIRST SECOND THREE #1 33688812 28 29 28.3 #2 3380 10 NA NA A.K. On Wednesday, February 26, 2014 3:06 AM, Mat wrote: thanks for the help up to here. A little problem remains. I have different "ABNR", if i try it with another ABNR, the Column extend for each ABNR, it should start with "FIRST" again. dat1 <- read.table(text="FS_ID ABNR 9327 33688812 11391 33688812 11392 33688812 11388 33688812 11390 33688812 12028 33688812 12029 33688812 1 3380",sep="",header=TRUE) dat2 <- read.table(text="FS_ID DATE POST 11390 2012-12-13 28 12029 2013-01-17 28.3 11391 2011-02-20 29 1 2014-02-20 10",header=TRUE,stringsAsFactors=FALSE) library(reshape2) setNames(dcast(merge(dat1,dat2, by="FS_ID")[,-1],ABNR~DATE,value.var="POST"),c("ABNR","FIRST","SECOND")) ABNR FIRST SECOND THREE NA 1 33688812 29 28 28.3 NA 2 3380 NA NA NA 10 it shoult start for each ABNR in the "FIRST"-Column again. Right would be: ABNR FIRST SECOND THREE 1 33688812 29 28 28.3 2 3380 10 NA NA Thank you. -- View this message in context: http://r.789695.n4.nabble.com/combine-2-data-frames-in-dependence-of-the-ID-tp4685781p4685855.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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 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] multcomp Westfall use up RAM memory
Hi, I have been running successfully Westfall procedures to adjust p-values in multiple comparisons. However, the last model I tried consumes too much memory (>40 Gb). Is there a way to reduce memory requirements? Or a workaround to run multiple comparison tests with Westfall procedures? Mind that I don't fully understand what's going on on the Westfall procedure implemented. So sorry in advance if this is a stupid question. Here is the script I am running: require("nlme") require("multcomp") dt_wide <- data.frame( Subj=1:44, Status=factor(rep(c("D","S","B","D","S","B"), c(7,7,6,8,8,8))), Treatment=factor(rep(c("St","Un"), c(20,24))), day1=rnorm(44,4,0.5), day2=rnorm(44,4,0.5), day3=rnorm(44,4,0.5)) dt_wide[,4:6] <- apply(dt_wide[,4:6], 2, function(x) {x[sample(1:44, sample(0:3))] <- NA;x}) dt_long <- reshape(dt_wide, idvar="Subj", times=names(dt_wide)[4:6], timevar="Time", varying=list(names(dt_wide)[4:6]), v.names="Values", direction="long") dt_long$Int <- with(dt_long, interaction(Status, Time, Treatment)) fm <- lme(Values ~ Int, data=dt_long, random= ~1 |Subj, na.action="na.omit") K<-rbind("1; St: D-S "=c(0,-1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "1; St: B-D "=c(0,-1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "1; St: B-S "=c(0, 0,-1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "1; Un: S-D "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 0, 0, 0, 0), "1; Un: B-D "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 1, 0, 0, 0, 0, 0), "1; Un: B-S "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 0, 0, 0), "2; St: S-D "=c(0, 0, 0, 0,-1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "2; St: B-D "=c(0, 0, 0, 0,-1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "2; St: B-S "=c(0, 0, 0, 0, 0,-1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "2; Un: S-D "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 0), "2; Un: B-D "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 1, 0, 0), "2; Un: B-S "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0), "3; St: S-D "=c(0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0), "3; St: B-D "=c(0, 0, 0, 0, 0, 0, 0,-1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0), "3; St: B-S "=c(0, 0, 0, 0, 0, 0, 0, 0,-1, 1, 0, 0, 0, 0, 0, 0, 0, 0), "3; Un: S-D "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 1), "3; Un: B-D "=c(0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-1), "3; Un: B-S "=c(0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2), "D; 1: Un-St"=c(0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0), "S; 1: Un-St"=c(0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0), "B; 1: Un-St"=c(0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0), "D; 2: Un-St"=c(0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0), "S; 2: Un-St"=c(0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0), "B; 2: Un-St"=c(0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0), "D; 3: Un-St"=c(0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0), "S; 3: Un-St"=c(0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 0, 0, 0, 0, 0, 1), "B; 3: Un-St"=c(0,-1,-1,-1,-1,-1,-1,-1,-1,-2,-1,-1,-1,-1,-1,-1,-1,-1), "D; St: 2-1 "=c(0,-1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "D; Un: 2-1 "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 1, 0, 0, 0, 0), "S; St: 2-1 "=c(0, 0,-1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "S; Un: 2-1 "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 1, 0, 0, 0), "B; St: 2-1 "=c(0, 0, 0,-1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "B; Un: 2-1 "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 1, 0, 0), "D; St: 3-2 "=c(0, 0, 0, 0,-1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), "D; Un: 3-2 "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 1, 0), "S; St: 3-2 "=c(0, 0, 0, 0, 0,-1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0), "S; Un: 3-2 "=c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1, 0, 0, 1), "B; St: 3-2 "=c(0, 0, 0, 0, 0, 0,-1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0), "B; Un: 3-2 "=c(0,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-2,-1,-1)) colnames(K) <- names(fixef(fm)) mc <- glht(fm, linfct=K) summary(mc,test=adjusted(type="Westfall")) Thanks, Joao __ R-help@r-project.org mailing list 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] combine 2 data.frames in dependence of the ID
Hi Mat, Please check the str() of your dat2. If I change dat2$DATE <- as.POSIXlt(dat2$DATE) dcast(ddply(merge(dat1,dat2,by="FS_ID")[,-1],.(ABNR), mutate, DATE=seq_along(DATE)),ABNR~DATE,value.var="POST") #Error in attributes(out) <- attributes(col) : # 'names' attribute [9] must be the same length as the vector [3] A.K. On Wednesday, February 26, 2014 9:57 AM, Matthias Weber wrote: Thanks first for the help, Your description works with the example perfect. If I try it with my data, there is an error. error in attributes(out) <- attributes(col) : attribute 'names' [306] must have the same length, than the vector [1] My data.frame "dat2" has 306 lines, could be this the reason? What does R mean with the vector? Thanks a lot for the help. Best regards. Mat. -Ursprüngliche Nachricht- Von: arun [mailto:smartpink...@yahoo.com] Gesendet: Mittwoch, 26. Februar 2014 10:08 An: Matthias Weber Betreff: Re: [R] combine 2 data.frames in dependence of the ID #or you could do: dcast(ddply(merge(dat1,dat2,by="FS_ID")[,-1],.(ABNR), mutate, DATE=cut(seq_along(DATE),breaks=c(0,1,2,3,4,5,6,7,8,9),labels=c("FIRST","SECOND","THREE","FOUR","FIVE","SIX","SEVEN","EIGHT","NINE"))),ABNR~DATE,value.var="POST") # ABNR FIRST SECOND THREE #1 33688812 28 29 28.3 #2 3380 10 NA NA A.K. On Wednesday, February 26, 2014 3:58 AM, arun wrote: Try: library(plyr) library(reshape2) res <- dcast(ddply(merge(dat1,dat2,by="FS_ID")[,-1],.(ABNR), mutate, DATE=seq_along(DATE)),ABNR~DATE,value.var="POST") colnames(res)[-1] <- c("FIRST","SECOND","THREE") res # ABNR FIRST SECOND THREE #1 33688812 28 29 28.3 #2 3380 10 NA NA A.K. On Wednesday, February 26, 2014 3:06 AM, Mat wrote: thanks for the help up to here. A little problem remains. I have different "ABNR", if i try it with another ABNR, the Column extend for each ABNR, it should start with "FIRST" again. dat1 <- read.table(text="FS_ID ABNR 9327 33688812 11391 33688812 11392 33688812 11388 33688812 11390 33688812 12028 33688812 12029 33688812 1 3380",sep="",header=TRUE) dat2 <- read.table(text="FS_ID DATE POST 11390 2012-12-13 28 12029 2013-01-17 28.3 11391 2011-02-20 29 1 2014-02-20 10",header=TRUE,stringsAsFactors=FALSE) library(reshape2) setNames(dcast(merge(dat1,dat2, by="FS_ID")[,-1],ABNR~DATE,value.var="POST"),c("ABNR","FIRST","SECOND")) ABNR FIRST SECOND THREE NA 1 33688812 29 28 28.3 NA 2 3380 NA NA NA 10 it shoult start for each ABNR in the "FIRST"-Column again. Right would be: ABNR FIRST SECOND THREE 1 33688812 29 28 28.3 2 3380 10 NA NA Thank you. -- View this message in context: http://r.789695.n4.nabble.com/combine-2-data-frames-in-dependence-of-the-ID-tp4685781p4685855.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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 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] SEs rms cph vs survey svycoxph
Ok. That's weird. If the stage= variables are indicators for levels of a factor their cph standard errors look a bit small for 102 events. Could you show what coxph() gives? It has both the model-based and robust standard errors. I've just tried an example with fairly extreme weights and svycoxph() still agrees with coxph() up to the expected factor of n/(n-1) -thomas On Tue, Feb 25, 2014 at 6:21 PM, Nathan Pace wrote: > Here are the model outputs. > > Nathan > > Survey package > > ca.ATE.design <- svydesign(ids = ~ id, weights = ~ get.weights(ca.ATE.ps, > stop.method = 'ks.mean'), data = ca.dt) > Independent Sampling design (with replacement) > > svydesign(ids = ~id, weights = ~get.weights(ca.ATE.ps, stop.method = > "ks.mean"), > data = ca.dt) > > > > > ca.ATE.dexmg.svy > Call: > svycoxph(formula = Surv(daysfromsurgerytodeath, as.logical(deceased)) ~ > dexamethasonemg + paincontrol + histgrade + adjuvant + stage + > anesthetictransfusionunits, design = ca.ATE.design) > > > coef exp(coef) se(coef) z p > dexamethasonemg-0.0863 0.917 0.0339 -2.550 1.1e-02 > paincontrolNot Epidural 0.6027 1.827 0.2370 2.543 1.1e-02 > histgradeg2 0.9340 2.545 0.4307 2.168 3.0e-02 > histgradeg3 1.2749 3.578 0.4453 2.863 4.2e-03 > adjuvantyes-0.5810 0.559 0.2529 -2.298 2.2e-02 > stageib-0.4394 0.644 0.6056 -0.726 4.7e-01 > stageiia1.6565 5.241 0.5193 3.190 1.4e-03 > stageiib1.6928 5.435 0.4902 3.453 5.5e-04 > stageiii1.8211 6.179 0.5130 3.550 3.9e-04 > stageiv 2.325110.227 0.6940 3.350 8.1e-04 > anesthetictransfusionunits 0.1963 1.217 0.0400 4.908 9.2e-07 > > Likelihood ratio test= on 11 df, p= n= 144, number of events= 102 > > rms package > > > ca.ATE.dexmg.rms2 > > Cox Proportional Hazards Model > > cph(formula = Surv(daysfromsurgerytodeath, as.logical(deceased)) ~ > dexamethasonemg + paincontrol + histgrade + adjuvant + stage + > anesthetictransfusionunits + cluster(id), data = ca.dt, > weights = get.weights(ca.ATE.ps, stop.method = "ks.mean"), > robust = T, x = T, y = T, se.fit = T, surv = T, time.inc = 30) > > Model Tests Discrimination > Indexes > Obs 144LR chi2117.80R2 0.559 > Events102d.f. 11Dxy -0.459 > Center 2.4016Pr(> chi2) 0.g1.083 > Score chi2 122.57gr 2.953 > Pr(> chi2) 0. > >CoefS.E. Wald Z Pr(>|Z|) > dexamethasonemg-0.0863 0.0192 -4.49 <0.0001 > paincontrol=Not Epidural0.6027 0.1203 5.01 <0.0001 > histgrade=g20.9340 0.2209 4.23 <0.0001 > histgrade=g31.2749 0.2612 4.88 <0.0001 > adjuvant=yes -0.5810 0.1741 -3.34 0.0008 > stage=ib -0.4394 0.1899 -2.31 0.0207 > stage=iia 1.6565 0.2097 7.90 <0.0001 > stage=iib 1.6928 0.1979 8.55 <0.0001 > stage=iii 1.8211 0.2411 7.55 <0.0001 > stage=iv2.3251 0.1886 12.33 <0.0001 > anesthetictransfusionunits 0.1964 0.0214 9.17 <0.0001 > > > > > > From: Thomas Lumley > Date: Tuesday, February 25, 2014 at 3:09 PM > To: "Nathan Leon Pace, MD, MStat" > Cc: r help list > Subject: Re: [R] SEs rms cph vs survey svycoxph > > > On Tue, Feb 25, 2014 at 2:51 PM, Nathan Pace > wrote: > > I¹ve used twang to get ATE propensity scores. > > I¹ve done multivariable, case weighted Cox PH models in survey using > svycoxph and in rms using cph with id(cluster) set to get robust estimates. > > The model language is identical. > > The point estimates are identical, but the CIs are considerably wider with > svycoxph estimates. > > There is a note in the svycoxph help page stating the SEs should agree > closely unless the model fits poorly. > > > > > The actual note on the svycoxph help page says > "The standard errors agree closely with survfit.coxph for independent > sampling when the model fits well, but are larger when the model fits > poorly. " > That is, the note is for the survival curve rather than the coefficients. > > It's still surprising that there's a big difference, but I think we need > more information. > >-thomas > > > -- > Thomas Lumley > Professor of Biostatistics > University of Auckland > > -- Thomas Lumley Professor of Biostatistics University of Auckland [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] Discrepant lm() and survreg() standard errors with weighted fits
The robust variances are a completely different estimate of standard error. For linear models the robust variance has been rediscovered many times and so has lots of names: the White estimate in economics, the Horvitz-Thompson in surveys, working independence esitmate in GEE models, infinitesimal jackknife in stat literature, But it is not the MLE estimate. When the robust estimate was added to survreg (and coxph) I made the decision that IF someone was invoking the robust variance, AND they were using weights, that simple case weights were unlikely to be what they had. So I chose to make treat the weights as sampling or precision weights, in contraindication to the longer standing behavior of coxph/survreg without a robust argument. Looking back, I probably should have taken one step further and changed the routines' behavior globally on the presumption that true case weights are vanishingly rare. They were not uncommon in my computing youth, when computer memory of < 64KB was usual (max possible on the PDP-11 architecture). But one is always cautious about non-backwards compatable changes. begin included message - When I use robust=T, I do not understand how survreg treats the weights as sampling weights and arrives at a different standard error from lm: summary(survreg(Surv(y)~x, dist='gaussian', data=test, weights=rep(2,6), robust=T))$table Value Std. Err (Naive SE)zp (Intercept) 0.400 0.29426260 0.5219013 1.35933 1.740420e-01 x0.8857143 0.08384353 0.1340119 10.56390 4.380958e-26 Log(scale) -0.2321528 0.08117684 0.2041241 -2.85984 4.238543e-03 __ R-help@r-project.org mailing list 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] Error message in `fitdistr` function in the MASS package
I have one issue at the moment while I am using a function, fitdistr in package MASS. I have 12 years of wind data with 30 min average interval. My data look like below: Timewindspeed 1/01/2005 0:00 15 1/01/2005 0:30 11 1/01/2005 1:00 11 1/01/2005 1:30 13 1/01/2005 2:00 15 1/01/2005 2:30 13 1/01/2005 3:00 13 1/01/2005 3:30 13 1/01/2005 4:00 15 1/01/2005 4:30 17 1/01/2005 5:00 17 1/01/2005 5:30 15 1/01/2005 6:00 13 1/01/2005 6:30 13 1/01/2005 7:00 15 1/01/2005 7:30 18 1/01/2005 8:00 18 1/01/2005 8:30 21 1/01/2005 9:00 21 1/01/2005 9:30 22 1/01/2005 10:00 24 1/01/2005 10:30 26 1/01/2005 11:00 24 1/01/2005 11:30 24 1/01/2005 12:00 24 1/01/2005 12:30 24 1/01/2005 13:00 17 1/01/2005 13:30 18 1/01/2005 14:00 21 1/01/2005 14:30 21 1/01/2005 15:00 22 1/01/2005 15:30 24 1/01/2005 16:00 24 1/01/2005 16:30 24 1/01/2005 17:00 21 1/01/2005 17:30 24 1/01/2005 18:00 22 1/01/2005 18:30 22 1/01/2005 19:00 21 1/01/2005 19:30 21 1/01/2005 20:00 15 1/01/2005 20:30 11 1/01/2005 21:00 13 My intention of using this function is to get daily Weibull parameters (shape and scale) but it keeps giving me errors. The code I put was: walpeup_alldata <- read.csv("walpeup_excercise.csv", header=TRUE, sep=",") walpeup_alldata$Date <- as.POSIXct(walpeup_alldata$Time, format = "%d/%m/%Y %H:%M", tz = "Australia/Melbourne") walpeup_alldata$day_index <- paste(format(walpeup_alldata$Date, "%Y"), format(walpeup_alldata$Date, "%j"), sep = "_") walpeup_aggregation <- aggregate(walpeup_alldata$windspeed, by=list(walpeup_alldata$day__index), FUN= function(x) {fitdistr(x, densfun="weibull")} ) Interesting thing is when I used short duration of wind data, the code works but produces lots of residuals. The residuals are like this. 33 2005_033c(4.75967037103778, 36.0492072865698) 34 2005_034c(7.71303917850763, 35.3491854177213) 35 2005_035c(5.68407836144938, 28.721154798025) 36 c(0.485695856927515, 0.720482566441891) 37 c(0.479982752982148, 0.605561818452758) 38 c(0.398017326464339, 0.975977176044699) 39 c(0.603493688481038, 1.04186250740921) 40 c(0.787847162718371, 0.600969267921991) 71 c(0.235900465436553, 0.110092730139038, 0.110092730139038, 0.519095128546693) 72 c(0.230383443160322, 0.094083878067012, 0.094083878067012, 0.366705115967811) 73 c(0.15841779216582, 0.127050034063599, 0.127050034063599, 0.952531448160185) 106-144.261676847584 107-134.931368456724 108-155.386471593028 109-163.984332061118 172 48 173 48 174 48 175 48 However when I increase size of the data by more than few months, it starts not to work again with providing below error message. *Error in fitdistr(x, densfun = "weibull") : optimization failed In addition: There were 50 or more warnings (use warnings() to see the first 50)* I have taken out all zero values in advance. It worked well for another dataset. I don't know what the cause and the solution for the data are at the moment. Thank you for your attention. -- View this message in context: http://r.789695.n4.nabble.com/Error-message-in-fitdistr-function-in-the-MASS-package-tp4685862.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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] Team Foundation Server with R
Hello all My upcoming project involves getting the live data from the Team Foundation Server. I goggled it how to get the data from TFS server via R-Script. But could not find any satisfactory result. If anyone has worked with the similar scenario, can you please give me a head start or else point to right direction. Any assistance would be appreciated. Regards Koushik Saha [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] (no subject)
Hi Dila, Try: transform(melt(dat,id.var="Day"),Month=match(variable,month.abb),Year=2012,Amount=value)[,-c(2:3)] A.K. On Tuesday, February 25, 2014 11:41 PM, dila radi wrote: Dear Arun, sorry for asking again. Assume that we used the sama data set dat <- read.table(text="Day Jan Feb Mar Apr 1 0 2.5 0.5 2 2 0 6.5 0 29 3 0 9.5 0 0 4 0 0 8 0.5 5 0 5 0.5 110.5 6 0 4 3.5 22 7 11 0 12.5 3.5 8 0 5 8 36.5",sep="",header=TRUE) But now, I want to split the date into Day, Month and Year as follow: Day Month Year Amount 1 1 2012 0.0 2 1 2012 0.0 3 1 2012 0.0 .. How do I achieved that? Thank you so much. Regards, Dila On 24 February 2014 20:32, arun wrote: > >Hi Dila, >Glad to know it works. >Regards, >Arun > > >On Monday, February 24, 2014 10:59 PM, dila radi wrote: > >Thank you Arun. I already tried it and it works!! Thank you so much. > > > >On 24 February 2014 19:47, arun wrote: > >Hi, >>Try: >>Assuming your dataset looks like below (please use ?dput) >> >>dat <- read.table(text="Day Jan Feb Mar Apr >> 1 0 2.5 0.5 2 >> 2 0 6.5 0 29 >> 3 0 9.5 0 0 >> 4 0 0 8 0.5 >> 5 0 5 0.5 110.5 >> 6 0 4 3.5 22 >> 7 11 0 12.5 3.5 >> 8 0 5 8 36.5",sep="",header=TRUE) >>library(reshape2) >> >>res <- >>transform(melt(dat,id.var="Day"),Date=paste(Day,match(variable,month.abb),2012,sep="/"),Amount=value)[,-c(1:3)] >>A.K. >> >> >> >> >> >>On Monday, February 24, 2014 10:20 PM, dila radi wrote: >>Hi all, >> >>I have a data set in this form: >> >>Year: 2012 >>Day Jan Feb Mar Apr 1 0 2.5 0.5 2 2 0 6.5 0 29 3 0 9.5 0 0 4 0 0 8 0.5 >>5 0 5 0.5 110.5 6 0 4 3.5 22 7 11 0 12.5 3.5 8 0 5 8 36.5 >>I want to rearrange the data in this form: >> >> Date Amount >>1/1/2012 0 >>2/1/2012 0 >>3/1/2012 0 >>4/1/2012 0 >>... ... >>... ... >> >>How can I achieve this? >> >>Thank you in advanced! >> >>Regards, >>Dila >> >> [[alternative HTML version deleted]] >> >>__ >>R-help@r-project.org mailing list >>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 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] libPaths how to change (R 3.0.2 64bit, RStudio 0.98.501, Windows 7)
What you are really asking is how environment variables get set outside of R, which is very OS-specific and not on topic here, and there can be numerous ways for it to happen even on a single OS. I will warn you that the path syntax can vary in Windows depending on where it gets set so beware of ~ expansion (doesn't always work) and forward/back-slash distinctions. You can start looking in the System control panel under Advanced and Environment Variables... you will probably need Admin privileges to go there. Google is your friend. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On February 25, 2014 10:57:00 AM PST, "Lopez, Dan" wrote: >R Experts, > >I had a problem when trying to install package tm. The install looked >successful ("Package 'tm' successfully unpacked and MD5 sums checked") >but I could not load it through >library(tm). It kept complaining that tm package was not installed. > >So it was through this problem that I realized I had two locations >where my packages are stored: >C:R/R-3.0.2/library #Preferred >lab.gov/users/lopez/Data/documents/R/win-library/3.0 #NOT >Preferred > >I am not sure when and how the second location was created. But now I >want to change my default location to the "Preferred" location. > >I referred to >http://stat.ethz.ch/R-manual/R-devel/library/base/html/libPaths.html >but I don't understand how to set the environment variables R_LIBS or >R_LIBS_SITE, which is what I understood I need to do. I looked in >R\R-3.0.2\etc and did not find a Renviron file (per >http://mathematicalcoffee.blogspot.com/2013/04/getting-rstudio-to-include-your.html). >So I created one (file name exactly as "Renviron") and set the variable >(R_LIBS_USER=~/R/library) there but when I do the following I still see >both library paths: > > .libPaths() >[1] "lab.gov/users/lopez/Data/documents/R/win-library/3.0" >"C:/R/R-3.0.2/library" > >I only want the preferred path. How do I remove the unwanted path? > >BTW I did find a solution to installing tm properly but want to prevent >similar problem from happening in the future by only having one library >path. > >Dan Lopez >Workforce Analyst >HRIM - Workforce Analytics & Metrics >Strategic Human Resources Management >(925) 422-0814 > > > > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list >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 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] Fitting glm with maxit=0?
Dear All, Does anyone know if there is any way to obtain the variance-covariance matrix for any arbitrarily given estimates with the glm() function? Here is what I really want. Given an arbitrary estimate (i.e., as starting points with the start= argument), the glm() function could return the corresponding variance-covariance matrix (or Hessian) and other quantities with no Netwon-Raphson iteration? This could have been done by setting maxit=0, but very unfortunately that is not an option in glm.control(). To illustrate the problem, mydata <- read.csv("http://www.ats.ucla.edu/stat/data/binary.csv";) beta0 <- 1:3 control0 <- glm.control(epsilon = 1e10, maxit = 0, trace = FALSE) fit <- glm(admit ~ gre + gpa, data = mydata, family = "binomial", start=beta0, control=control0) summary(fit)$"cov.scaled" By the way, I am aware that I could directly compute the covariance matrix using the formula. I also know that I could extract the corresponding deviance by using the offset option. Any suggestion is greatly appreicated. Thanks, Xiaogang Su = Xiaogang Su, Ph.D. Associate Professor Department of Mathematical Sciences University of Texas at El Paso 500 W. University Ave. El Paso, Texas 79968-0514 x...@utep.edu xiaogan...@gmail.com https://sites.google.com/site/xgsu00/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list 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] combine 2 data.frames in dependence of the ID
thanks for the help up to here. A little problem remains. I have different "ABNR", if i try it with another ABNR, the Column extend for each ABNR, it should start with "FIRST" again. dat1 <- read.table(text="FS_ID ABNR 932733688812 11391 33688812 11392 33688812 11388 33688812 11390 33688812 12028 33688812 12029 33688812 1 3380",sep="",header=TRUE) dat2 <- read.table(text="FS_ID DATE POST 11390 2012-12-1328 12029 2013-01-1728.3 11391 2011-02-2029 1 2014-02-2010",header=TRUE,stringsAsFactors=FALSE) library(reshape2) setNames(dcast(merge(dat1,dat2, by="FS_ID")[,-1],ABNR~DATE,value.var="POST"),c("ABNR","FIRST","SECOND")) ABNR FIRST SECOND THREE NA 1 3368881229 28 28.3 NA 2 3380NA NANA 10 it shoult start for each ABNR in the "FIRST"-Column again. Right would be: ABNR FIRST SECOND THREE 1 3368881229 28 28.3 2 338010 NANA Thank you. -- View this message in context: http://r.789695.n4.nabble.com/combine-2-data-frames-in-dependence-of-the-ID-tp4685781p4685855.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.