[R] Time outside limits
Hi, I'm currently facing the problem that I need to write a function where I get a dataframe back which contains the time (in hours) outside the limits of a temperature sensor, each month, and for how long exactly. I wrote a for loop which check:- if a datapoint is outside the limit- if the previous datapoint is outside the limt, then count + 1- if the next datapoint isn't outside: write in dataframe. I guess this could be with some vectorisation function, I tried with seq_along, and match, but couldn't figure it out. Here some sample data: y <- c(rnorm(10,25), rnorm(10,32),rnorm(10,25), rnorm(10,20), rnorm(10,25))x <- seq(c(ISOdate(2000,3,20)), by = "hour", length.out = length(y)) limits of y: c(22,27) Thanks Bart [[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] Animate dataframe
Hi, sorry for the double posting, but it seems my text was gone... I'm running a code which does some alignment between data. Now I want to follow the alignment while looping over the data. I'm aware of the animation package, and saw the (easy) example where a plot is animated by calling 100 times plot. Is it possible to use this trick also for printing a dataframe to the graphics device? I tried already addtable2plot, but the table doesn't fit in the graphics device (or I'm doing something wrong). Here a simplified example of how the data looks and how it is filled: dat <- data.frame(rows=rep(1:10, 15), columns=rep(1:15, each=10), result=NA) dat$result <- NA i = 0 while (!all(!is.na(dat$result))) { i = i + 1 if (i==100) break dat$result[sample(1:nrow(dat),1)] <- rnorm(1) } in each loop should be something like: print(as.data.frame(tapply(dat$result,list(rows=dat$rows,columns=dat$columns), function(x) paste(x[x!=""],collapse="/" Thanks Bart PS: I know that I can use a for loop instead of the while and if (i==100) break construction, but hey, its an example, right? ;-) __ 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] animate dataframe
Hi, I'm running a code which does some alignment between data. Now I want to follow the alignment while looping over the data. I'm aware of the animation package, and saw the (easy) example where a plot is animated by calling 100 times plot. Is it possible to use this trick also for printing a dataframe to the graphics device? I tried already addtable2plot, but the table doesn't fit in the graphics device (or I'm doing something wrong). Here a simplified example of how the data looks and how it is filled: dat <- data.frame(rows=rep(1:10, 15), columns=rep(1:15, each=10), result=NA) dat$result <- NA i = 0 while (!all(!is.na(dat$result))) { i = i + 1 if (i==100) break dat$result[sample(1:nrow(dat),1)] <- rnorm(1) } in each loop should be something like: print(as.data.frame(tapply(dat$result,list(rows=dat$rows,columns=dat$columns), function(x) paste(x[x!=""],collapse="/" Thanks Bart PS: I know that I can use a for loop instead of the while and if (i==100) break construction, but hey, its an example, right? ;-) [[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] sorting/grouping/classification problem?
Hi, after all, brute force seems the way to go. I will use a simplified example to illustrate what I want (dump of dat4 is below): suppose dat4: ID rrt Mnd Result 1 0.45 00.1 1 0.48 00.3 1 1.24 00.5 2 0.45 30.2 2 0.48 30.6 2 1.22 30.4 I want to generate all possible combinations of Mnd 0 with Mnd 3 to calculate the sum of the squared differences divided by the number of rrt's eg: Mnd 0 rrt 0.45 gives result 0.1 where Mnd 3 rrt 0.45 gives 0.2 At the same time rrt 0.48 at Mnd 0 gives 0.3 where rrt 0.48 at Mnd 3 gives 0.6 The same for rrt 1.24 at Mnd 0: 0.5 This gives (0.1-0.2) ^2 + (0.3-0.6)^2 + The permutations should follow this rules: - rrt's can never differ more than 10% - rrt's can never switch (eg if rrt 0.45 at 0 Mnd is coupled to 0.48 mnd at 3 Mnd, then 0.48 at 0Mnd can not be coupled to 0.45 at 3 Mnd) - rrt's can be coupled to NA values and shouldn't be coupled necessarily. I already played with combn, and expand.grid, but couldn't figure out how to generate the combinations... The goal is to minimize the resulting value, but be aware of the fact that the problem above is simplified, and thus isn't limited to only 2 Mnd values, but maybe 5 - 10. Thanks Bart dat4 <- structure(list(ID = c(1L, 1L, 1L, 2L, 2L, 2L), rrt = c(0.45, 0.48, 1.24, 0.45, 0.48, 1.22), Mnd = c(0L, 0L, 0L, 3L, 3L, 3L ), Result = c(0.1, 0.3, 0.5, 0.2, 0.6, 0.4)), .Names = c("ID", "rrt", "Mnd", "Result"), row.names = c(NA, 6L), class = "data.frame") [[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] sorting/grouping/classification problem?
Hi, To clarify further: these are results for degradation studies. We search for degradations at 0 months, again at 3 months, again at 6 months, ... Each analysis gives us a rrt, and a result. To make final conclusions, we have to align the results manually (at least for now). rrt is dependend on lots of factors, so there is a bit of variation there (eg 0.48 at 0 months, 0.46 at 6 months, and again 0.48 at 9 months). If you take a look at the sample data, you can see that the degradation with rrt 0.48 is increasing within time, so you can clearly see that 0.48 and 0.46 are essentially the same degradant. But rounding alone doesn't solve it all, as this can match the 0.46 at 6 months to the degradant with rrt 0.45 at 0 months, and this will give a really odd trend line for that degradant. I was thinking about making a list of all rrt's, calculation every possible combination of shuffling within certain limits (eg max 10% or so), calculate r2 for each combination and maximize? Seems so brute force and low elegant? Bart > Date: Fri, 25 Jan 2013 10:01:44 -0800 > From: smartpink...@yahoo.com > Subject: Re: [R] sorting/grouping/classification problem? > To: bartjoo...@hotmail.com > CC: djmu...@gmail.com; r-help@r-project.org > > Hi, > > Your question is bit confusing to me. > When you say that "which rrts are the same, and which are the new ones", > to me it looks like "0.35, 0.36" are new addition to Mnd at time points 6 and > 9. > Extending Dennis' solution: > Just for understanding the problem: > vec1<-c(0.45,0.48,1.24,1.22,0.44,0.46,1.21) > dat$newCol<-ifelse(dat$rrt%in%vec1,"old","new") > dcast(dat,Time+newCol~Mnd,value.var="Result") > #Time newCol 0 369 > #1 0.3550new NA NA 0.05 0.06 > #2 0.4475old 0.1 0.2 0.40 0.60 > #3 0.4750 old 0.3 0.6 1.20 1.80 > #4 1.2225old 0.5 0.4 0.45 0.50 > A.K. > > > > > > - Original Message - > From: Bart Joosen > To: Dennis Murphy ; r-help@r-project.org > Cc: > Sent: Friday, January 25, 2013 1:48 AM > Subject: Re: [R] sorting/grouping/classification problem? > > Nice suggestion for the extra "Time" column. > > But I think I didn't ask clear enough my problem. > My main problem is to find a way to "classify" the rrt's, so that we don't > have to check each dataframe by our selfs. > > So I need a function that fills in the extra "Time" column by taking a look > at the rrt's (and maybe the results), and take the discision which rrts are > the same, and which are new ones. > > As stated: rrt's never switch place, and results can't be concatenated or > averaged within a Mnd. > > I hope my question is a bit more clear now. > > Thank you all for your suggestions > > Bart > > > Date: Thu, 24 Jan 2013 15:01:40 -0800 > > Subject: Re: [R] sorting/grouping/classification problem? > > From: djmu...@gmail.com > > To: bartjoo...@hotmail.com > > > > Hi: > > > > Here's a potential workaround: > > > > # Add a time order variable > > dat$ord <- c(rep(2:4, 2), rep(1:4, 2)) > > > > # Average rrt by ord > > dat$Time <- with(dat, ave(rrt, ord, FUN = mean)) > > dat > > > > # Reshape the data > > > > library(reshape2) > > > dcast(dat, Time ~ Mnd, value.var = "Result") > > Time 0 369 > > 1 0.3550 NA NA 0.05 0.06 > > 2 0.4475 0.1 0.2 0.40 0.60 > > 3 0.4750 0.3 0.6 1.20 1.80 > > 4 1.2225 0.5 0.4 0.45 0.50 > > > > You could always round dat$Time to two decimal places in its > > definition before doing the cast if you so desired. > > > > Dennis > > > > On Thu, Jan 24, 2013 at 11:31 AM, Bart Joosen > > wrote: > > > > > > Hi, > > > > > > > > > I'm a database admin for a database which manage chromatographic results > > > of products during stability studies. > > > I use R for the reporting of the results in MS Word through R2wd. > > > > > > > > > But now I think I need your help: > > > suppose we have the following data frame: > > > > > > > > >ID rrt Mnd Result > > > 1 0.45 0 0.10 > > > 1 0.48 0 0.30 > > > 1 1.24 0 0.50 > > > 2 0.45 3 0.20 > > > 2 0.48 3 0.60 > > > 2 1.22 3 0.40 > > > 3 0.35 6 0.05 > > > 3 0.44 6 0.40 > > > 3 0.46 6 1.20 > > > 3 1.21 6 0.45 > > > 4 0.36 9 0.06 > > > 4 0.45
Re: [R] sorting/grouping/classification problem?
Nice suggestion for the extra "Time" column. But I think I didn't ask clear enough my problem. My main problem is to find a way to "classify" the rrt's, so that we don't have to check each dataframe by our selfs. So I need a function that fills in the extra "Time" column by taking a look at the rrt's (and maybe the results), and take the discision which rrts are the same, and which are new ones. As stated: rrt's never switch place, and results can't be concatenated or averaged within a Mnd. I hope my question is a bit more clear now. Thank you all for your suggestions Bart > Date: Thu, 24 Jan 2013 15:01:40 -0800 > Subject: Re: [R] sorting/grouping/classification problem? > From: djmu...@gmail.com > To: bartjoo...@hotmail.com > > Hi: > > Here's a potential workaround: > > # Add a time order variable > dat$ord <- c(rep(2:4, 2), rep(1:4, 2)) > > # Average rrt by ord > dat$Time <- with(dat, ave(rrt, ord, FUN = mean)) > dat > > # Reshape the data > > library(reshape2) > > dcast(dat, Time ~ Mnd, value.var = "Result") > Time 0 369 > 1 0.3550 NA NA 0.05 0.06 > 2 0.4475 0.1 0.2 0.40 0.60 > 3 0.4750 0.3 0.6 1.20 1.80 > 4 1.2225 0.5 0.4 0.45 0.50 > > You could always round dat$Time to two decimal places in its > definition before doing the cast if you so desired. > > Dennis > > On Thu, Jan 24, 2013 at 11:31 AM, Bart Joosen wrote: > > > > Hi, > > > > > > I'm a database admin for a database which manage chromatographic results of > > products during stability studies. > > I use R for the reporting of the results in MS Word through R2wd. > > > > > > But now I think I need your help: > > suppose we have the following data frame: > > > > > >ID rrt Mnd Result > > 1 0.45 0 0.10 > > 1 0.48 0 0.30 > > 1 1.24 0 0.50 > > 2 0.45 3 0.20 > > 2 0.48 3 0.60 > > 2 1.22 3 0.40 > > 3 0.35 6 0.05 > > 3 0.44 6 0.40 > > 3 0.46 6 1.20 > > 3 1.21 6 0.45 > > 4 0.36 9 0.06 > > 4 0.45 9 0.60 > > 4 0.48 9 1.80 > > 4 1.22 9 0.50 > > > > > > > > ID is the database ID, rrt is an identifier for the result, Mnd is the > > timepoint of analysis and Result is... the result of the test. > > What I need is this dataframe in a wide format (which I managed with dat2 > > <- as.data.frame(tapply(dat$Result,list(rrt=dat$rrt,Mnd=dat$Mnd), > > function(x) paste(x[x!=""],collapse="/"))) ) > > But as you can see, rrt is not an exact identifier for the result. > > > > Sometimes rrt for 0 Mnd is 0.45, but at 6 Mnd the rrt is 0.44. > > Now I need the results to align so that one can easily see how rrt x is > > evolving within the Mnd time points. > > I tried with different rounding procedures (round every 0.02, check that no > > results are discarded this way, and check for alignment), but nothing seems > > to make some sense. > > Also tried checking the highest results in each Mnd, align these, determine > > correction factors for the rrt for all the other rrts, ... > > > > > > Some results will follow a trend (like rrt 0.45), some will remain more or > > less stable. > > But NEVER rrt will switch i with each other! > > > > > > > > > > Ultimately I need to update in the db, so I need a list/dataframe with the > > ID, the original rrt and the adjusted rrt (maybe the first occuring rrt, or > > the mean of the rrts, doesn't matter). > > > > > > > > > > Any ideas about which algorithms can be used? I searched on pubmed, but > > couldn't find anything > > > > > > > > > > Thanks > > > > > > Bart > > > > > > PS: to get the data: > > > > > > dat <- > > structure(list(ID = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, > > 4L, 4L, 4L, 4L), rrt = c(0.45, 0.48, 1.24, 0.45, 0.48, 1.22, > > 0.35, 0.44, 0.46, 1.21, 0.36, 0.45, 0.48, 1.22), Mnd = c(0L, > > 0L, 0L, 3L, 3L, 3L, 6L, 6L, 6L, 6L, 9L, 9L, 9L, 9L), Result = c(0.1, > > 0.3, 0.5, 0.2, 0.6, 0.4, 0.05, 0.4, 1.2, 0.45, 0.06, 0.6, 1.8, > > 0.5)), .Names = c("ID", "rrt", "Mnd", "Result"), class = "data.frame", > > row.names = c(NA, > > -14L)) > > > > > > > > resulting dataframe: > > dat3 <- > > structure(list(Time = c(0.355, 0.45, 0.48, 1.22), `0` = c(NA, > > 0.1, 0.3, 0.5), `3` = c(NA, 0.2, 0.6, 0.4),
Re: [R] sorting/grouping/classification problem?
dat3 is the dataframe where there are some rrt values merged, which is actually the problem: how on Earth discide which rows van be merged Thanks for your input! Bart -Original Message- From: arun Sent: 24 Jan 2013 20:18:28 GMT To: Bart Joosen Cc: R help Subject: Re: [R] sorting/grouping/classification problem? HI, If I understand your question, "dat3" is not you wanted. Is it something like this you wanted? library(reshape2) dcast(dat,rrt~Mnd,value.var="Result") # rrt 0 369 #1 0.35 NA NA 0.05 NA #2 0.36 NA NA NA 0.06 #3 0.44 NA NA 0.40 NA #4 0.45 0.1 0.2 NA 0.60 #5 0.46 NA NA 1.20 NA #6 0.48 0.3 0.6 NA 1.80 #7 1.21 NA NA 0.45 NA #8 1.22 NA 0.4 NA 0.50 #9 1.24 0.5 NA NA NA A.K. - Original Message ----- From: Bart Joosen To: r-help Cc: Sent: Thursday, January 24, 2013 2:31 PM Subject: [R] sorting/grouping/classification problem? Hi, I'm a database admin for a database which manage chromatographic results of products during stability studies. I use R for the reporting of the results in MS Word through R2wd. But now I think I need your help: suppose we have the following data frame: ID rrt Mnd Result 1 0.45 0 0.10 1 0.48 0 0.30 1 1.24 0 0.50 2 0.45 3 0.20 2 0.48 3 0.60 2 1.22 3 0.40 3 0.35 6 0.05 3 0.44 6 0.40 3 0.46 6 1.20 3 1.21 6 0.45 4 0.36 9 0.06 4 0.45 9 0.60 4 0.48 9 1.80 4 1.22 9 0.50 ID is the database ID, rrt is an identifier for the result, Mnd is the timepoint of analysis and Result is... the result of the test. What I need is this dataframe in a wide format (which I managed with dat2 <- as.data.frame(tapply(dat$Result,list(rrt=dat$rrt,Mnd=dat$Mnd), function(x) paste(x[x!=""],collapse="/"))) ) But as you can see, rrt is not an exact identifier for the result. Sometimes rrt for 0 Mnd is 0.45, but at 6 Mnd the rrt is 0.44. Now I need the results to align so that one can easily see how rrt x is evolving within the Mnd time points. I tried with different rounding procedures (round every 0.02, check that no results are discarded this way, and check for alignment), but nothing seems to make some sense. Also tried checking the highest results in each Mnd, align these, determine correction factors for the rrt for all the other rrts, ... Some results will follow a trend (like rrt 0.45), some will remain more or less stable. But NEVER rrt will switch i with each other! Ultimately I need to update in the db, so I need a list/dataframe with the ID, the original rrt and the adjusted rrt (maybe the first occuring rrt, or the mean of the rrts, doesn't matter). Any ideas about which algorithms can be used? I searched on pubmed, but couldn't find anything Thanks Bart PS: to get the data: dat <- structure(list(ID = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), rrt = c(0.45, 0.48, 1.24, 0.45, 0.48, 1.22, 0.35, 0.44, 0.46, 1.21, 0.36, 0.45, 0.48, 1.22), Mnd = c(0L, 0L, 0L, 3L, 3L, 3L, 6L, 6L, 6L, 6L, 9L, 9L, 9L, 9L), Result = c(0.1, 0.3, 0.5, 0.2, 0.6, 0.4, 0.05, 0.4, 1.2, 0.45, 0.06, 0.6, 1.8, 0.5)), .Names = c("ID", "rrt", "Mnd", "Result"), class = "data.frame", row.names = c(NA, -14L)) resulting dataframe: dat3 <- structure(list(Time = c(0.355, 0.45, 0.48, 1.22), `0` = c(NA, 0.1, 0.3, 0.5), `3` = c(NA, 0.2, 0.6, 0.4), `6` = c(0.05, 0.4, 1.2, 0.45), `9` = c(0.06, 0.6, 1.8, 0.5)), .Names = c("Time", "0", "3", "6", "9"), class = "data.frame", row.names = c(NA, -4L)) [[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] sorting/grouping/classification problem?
Hi, I'm a database admin for a database which manage chromatographic results of products during stability studies. I use R for the reporting of the results in MS Word through R2wd. But now I think I need your help: suppose we have the following data frame: ID rrt Mnd Result 1 0.45 0 0.10 1 0.48 0 0.30 1 1.24 0 0.50 2 0.45 3 0.20 2 0.48 3 0.60 2 1.22 3 0.40 3 0.35 6 0.05 3 0.44 6 0.40 3 0.46 6 1.20 3 1.21 6 0.45 4 0.36 9 0.06 4 0.45 9 0.60 4 0.48 9 1.80 4 1.22 9 0.50 ID is the database ID, rrt is an identifier for the result, Mnd is the timepoint of analysis and Result is... the result of the test. What I need is this dataframe in a wide format (which I managed with dat2 <- as.data.frame(tapply(dat$Result,list(rrt=dat$rrt,Mnd=dat$Mnd), function(x) paste(x[x!=""],collapse="/"))) ) But as you can see, rrt is not an exact identifier for the result. Sometimes rrt for 0 Mnd is 0.45, but at 6 Mnd the rrt is 0.44. Now I need the results to align so that one can easily see how rrt x is evolving within the Mnd time points. I tried with different rounding procedures (round every 0.02, check that no results are discarded this way, and check for alignment), but nothing seems to make some sense. Also tried checking the highest results in each Mnd, align these, determine correction factors for the rrt for all the other rrts, ... Some results will follow a trend (like rrt 0.45), some will remain more or less stable. But NEVER rrt will switch i with each other! Ultimately I need to update in the db, so I need a list/dataframe with the ID, the original rrt and the adjusted rrt (maybe the first occuring rrt, or the mean of the rrts, doesn't matter). Any ideas about which algorithms can be used? I searched on pubmed, but couldn't find anything Thanks Bart PS: to get the data: dat <- structure(list(ID = c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L), rrt = c(0.45, 0.48, 1.24, 0.45, 0.48, 1.22, 0.35, 0.44, 0.46, 1.21, 0.36, 0.45, 0.48, 1.22), Mnd = c(0L, 0L, 0L, 3L, 3L, 3L, 6L, 6L, 6L, 6L, 9L, 9L, 9L, 9L), Result = c(0.1, 0.3, 0.5, 0.2, 0.6, 0.4, 0.05, 0.4, 1.2, 0.45, 0.06, 0.6, 1.8, 0.5)), .Names = c("ID", "rrt", "Mnd", "Result"), class = "data.frame", row.names = c(NA, -14L)) resulting dataframe: dat3 <- structure(list(Time = c(0.355, 0.45, 0.48, 1.22), `0` = c(NA, 0.1, 0.3, 0.5), `3` = c(NA, 0.2, 0.6, 0.4), `6` = c(0.05, 0.4, 1.2, 0.45), `9` = c(0.06, 0.6, 1.8, 0.5)), .Names = c("Time", "0", "3", "6", "9"), class = "data.frame", row.names = c(NA, -4L)) [[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] puzzling RODBC error
It seems that your sqlTables also give no results. So there must be something wrong with the ODBC connect. I didn't use odbcConnectAccess, but made an ODBC connection, and then used ODBCconnect to connect to our database. Maybe you can define a user DSN and try it this way? Bart -- View this message in context: http://r.789695.n4.nabble.com/puzzling-RODBC-error-tp4650837p4650840.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] Import/Export excel files to/from R, without changing the file type
You should read your error messages more carefully, especially: could not find function! take a look at loadworkbook and loadWorkbook. Bart -- View this message in context: http://r.789695.n4.nabble.com/Import-Export-excel-files-to-from-R-without-changing-the-file-type-tp4650717p4650823.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] Creating dataframes with unique, sequential names
Damn, I didn't read that before but assign could get the job done if used wise, but without context it's hard to say, I must admit > Date: Tue, 30 Oct 2012 10:50:40 -0600 > Subject: Re: [R] Creating dataframes with unique, sequential names > From: 538...@gmail.com > To: bartjoo...@hotmail.com > CC: r-help@r-project.org > > On Tue, Oct 30, 2012 at 8:00 AM, Bart Joosen wrote: > > Take a look at ?assign > > Then read fortune(236) > > Then learn about lists and environments to learn better methods. > > > Bart, without context it is harder for use to contribute useful advice. > > > > > > Bart > > > > > > > > -- > > View this message in context: > > http://r.789695.n4.nabble.com/Creating-dataframes-with-unique-sequential-names-tp4647863p4647864.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 [[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] Creating dataframes with unique, sequential names
Take a look at ?assign Bart -- View this message in context: http://r.789695.n4.nabble.com/Creating-dataframes-with-unique-sequential-names-tp4647863p4647864.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] How to quit R script & return to R prompt
you can see it goes wrong at: > barplot(xtab(`profits,data=Forbes2000)) You typed a ` without closing it: barplot(xtab(`profits`,data=Forbes2000)) anyway: pushing the escape button should also return you to the R-prompt (at least on a Windows platform) -- View this message in context: http://r.789695.n4.nabble.com/How-to-quit-R-script-return-to-R-prompt-tp4647376p4647382.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] find similarity between two spectral profile
If you provide some data we can work with ("a reproducible example"), then we can help you. Now we can only guess? -- View this message in context: http://r.789695.n4.nabble.com/find-similarity-between-two-spectral-profile-tp4647157p4647319.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] struggling with R2wd or SWord? Try rtf!
Why does R2wd not work? I already got it working on a 64-bit PC, but I think you need a different statconn if I recall correctly. If you already have some scripts with R2wd, it's maybe easier to invest some time to get it working than switching to rtf. Anyway thanks for the tip, if I need it, I will digg into rtf. Bart -- View this message in context: http://r.789695.n4.nabble.com/struggling-with-R2wd-or-SWord-Try-rtf-tp4645899p4645978.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] Regular expressions: stuck again...
Hi, I'm currently reworking a report, originating from a MS Access database, but should be implemented in R. Now I'm facing the task to convert a lot of queries to postgreSQL. What I want to do is make a function which takes the MS Access query as an argument and returns the pgSQL version. So: SELECT [public_tblFiche].[Fichenr], [public_tblArtnr].[Artnr] FROM [public_tblFiche], [public_tblArtnr] WHERE [public_tblFiche].[Artnr_ID] = [public_tblArtnr].[Artnr_ID]; or SELECT public_tblFiche.Fichenr, public_tblArtnr.Artnr FROM public_tblFiche, public_tblArtnr WHERE public_tblFiche.Artnr_ID = public_tblArtnr.Artnr_ID; Should become: SELECT \"public\".\"tblFiche\".\"Fichenr\", \"public\".\"tblArtnr\".\"Artnr\" FROM \"public\".\"tblFiche\", \"public\".\"tblArtnr\" WHERE \"public\".\"tblFiche\".\"Artnr_ID\" = \"public\".\"tblArtnr\".\"Artnr_ID\"; concrete: The square backets [ and ] should removed and xxx_xxx.xxx should become \"xxx\".\"xxx\"\".\"xxx\" When only queries with square brackets, I used gsub('[', '\"', x, fixed=TRUE), gsub(']', '\"', x, fixed=TRUE), gsub('_', '\"', x, fixed=TRUE), But to do the trick with regular expressions, I cant get a grip on this Anyone who can give me some help? Thanks Bart -- View this message in context: http://r.789695.n4.nabble.com/Regular-expressions-stuck-again-tp4641155.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] On Reproducible Code
How about sending an email to the OP with a message like: "Hi, Thanks for submitting a question to the R-help list. We hope you did read the Posting Guide and submitted a reproducible example of your code (by the use of dput, structure, ...)." Then there is no need to add the message to the end of every message so that most of the people automatically skip reading the end of every message (at least I do) Just my 2 cents Bart -- View this message in context: http://r.789695.n4.nabble.com/On-Reproducible-Code-tp4637796p4638513.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] Automating R script with Windows 7
I would try first without the task scheduler: Make a .bat file and run this from the command line. This way you can see what is going on without the flashing window that is opened and closed immeadiately. maviney wrote > > > I tried to task schedule, using the following code > > "C:\Program Files\R\R-2.12.1\bin\i386\Rscript.exe" > > but the Rscript just flashes at me > > Thanks for ur assistance, its back to researching my problem > -- View this message in context: http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4635380.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] Automating R script with Windows 7
In R you should slashes instead of backslashes: C:\PROGRA~1\R\R-2.11.1\bin\RScript.exe C:/Users/Vincent/Documents/temp/test.r Bart -- View this message in context: http://r.789695.n4.nabble.com/Automating-R-script-with-Windows-7-tp4446693p4635260.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] Is it possible to remove this loop? [SEC=UNCLASSIFIED]
And one more alternative: a1$h2 <- apply(a1,1, function(x) if (x["h1"]=="H") 1 else 0 ) -- View this message in context: http://r.789695.n4.nabble.com/Is-it-possible-to-remove-this-loop-SEC-UNCLASSIFIED-tp4635250p4635271.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] Validation of R script when changing R version
Hi, a few years ago I wrote a script which grabs a .csv file and transforms this in a (beautifull) MS Word document, with all the calculations and plots required. All calculations in the report were verified manually against some datasets with known results to validate the use of the script, as this is required before we may use the script. Now we want to upgrade to R 2.15, but my script was validated under R 2.11. If my function would return just a dataset with some values, it would be easy to compare between both versions, but not when I have to read about 100 pages in a word document to check everything. How does one deal with this kind of situation? Or if it's not possible, how to avoid this kind of problems when output in MS Word is required? Thanks Bart -- View this message in context: http://r.789695.n4.nabble.com/Validation-of-R-script-when-changing-R-version-tp4633081.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] R2wd error in wdGet
I had this problem when my word was already open and asking for saving a file. So the VBA was already busy. Bart -- View this message in context: http://r.789695.n4.nabble.com/R2wd-error-in-wdGet-tp4632737p4633080.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] ANOVA Lack of fit test results not matching
Hi, we have a validated program to do our calculations, but sometime I want to use R to do some quick statistical calculations. But for our linearity test, I can't reproduce in R. Suppose the following data set: dat <- structure(list(Level = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L), .Label = c("A", "B", "C", "D", "E"), class = "factor"), x = c(1.6882, 1.8992, 2.1103, 2.3213, 2.5323, 1.791, 1.99, 2.189, 2.388, 1.592, 1.6, 1.8, 2, 2.2, 2.4 ), y = c(845467.4698, 951160.9668, 1059023.406, 1164772.671, 1267586.471, 885310.2247, 980398.3656, 1078975.303, 1174925.069, 785042.962, 802448.3644, 900011.1168, 998232.6022, 1098189.112, 1200127.806)), .Names = c("Level", "x", "y"), row.names = c(NA, -15L), class = "data.frame") Now I wanted to do a Lack of fit test (in our program: residual ANOVA). I did some searching, and found: anova(lm(y~x + Level, dat)) and look at the p-value for Level. But the resulting value (F value 0.0704) doesn't corresponds with the F value from our program (0.0599). Also the MS and SS values don't match. As it is called residual ANOVA, I tried to fit a model (mod <- lm(y~x,dat)) and then did a regression of Level agains the residuals of the model: anova (lm(resid(mod)~dat$Level)). But again no match. Also the degrees of freedom dont match anywhere (in our program: 3). Here is the table from our program, any ideas about how to come to this result? Source SS DF MS F-Ratio p-Value 1 Total 8.601108e+008 13 66162368.020 2 Error (Intra) 8.449211e+008 10 84492107.090 3 Model (Inter) 1.518971e+007 3 5063237.787 0.059926 0.979704 Thanks Bart -- View this message in context: http://r.789695.n4.nabble.com/ANOVA-Lack-of-fit-test-results-not-matching-tp4582774p4582774.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] Is it possible to de-select with sqlQuery from the RODBC library?
Another way is to use VBA to create a table which contains all the table names and column names. Then use select from this table to create your query. I didn't find any other solutions Bart -- View this message in context: http://r.789695.n4.nabble.com/Is-it-possible-to-de-select-with-sqlQuery-from-the-RODBC-library-tp4511189p4516276.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] Is it possible to de-select with sqlQuery from the RODBC library?
What you can do: "SELECT top 1 * FROM your_table;" Use this selection to find all your column names in R then paste everything together without the names you don't want and then run your query. Bart -- View this message in context: http://r.789695.n4.nabble.com/Is-it-possible-to-de-select-with-sqlQuery-from-the-RODBC-library-tp4511189p4511800.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] plotting average effects.
How about posting a reproducible sample, so that we can see what is going on? Read the posting guide!!! -- View this message in context: http://r.789695.n4.nabble.com/plotting-average-effects-tp3923982p3925324.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] Different Estimated values between R and Excel
I you had posted your code which gave the results, we would have seen that you switched your variables. Bart -- View this message in context: http://r.789695.n4.nabble.com/Different-Estimated-values-between-R-and-Excel-tp3762508p3762738.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] Year cost optimisation
Hi, I have a data file with all our purchases from last year, it contains the unit price, count, and total dollars spend. Now I'm looking for some way to "classify" all our purchases to find out which purchases are the best ones to find cheaper alternatives. for example: if we only buy 1 item of a product which costs 5 dollar, we maybe can find a cheaper product of 4.5 dollar, but this won't make it on our year budget. On the other hand, there may be some products of 2.5 dollar, but we purchased 1000ths of them, so 2.3 dollar/product can be a significant saving. Instead of searching for each of our products a cheaper alternative (takes a awfull lot of time), I would like to concentrate on a top 20 for example. Maybe calculate the pct contribution to the total budget, and take the top 20? Any other ideas for an approach? Here an example dataframe: dat <- data.frame(item=1:160, unit_price=round(c(runif(80,0,100), runif(80,250,1000)),2), count=round(c(runif(40, 1,10), runif(40,20,1000),runif(40, 1,10), runif(40,20,1000)),0), total=0) dat$total = dat$count*dat$unit_price Bart -- View this message in context: http://r.789695.n4.nabble.com/Year-cost-optimisation-tp3599538p3599538.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] Fibonacci
Another solution: while (Fibonacci[1] < 500) Fibonacci <- c(sum(Fibonacci[c(1,2)]), Fibonacci) While this adds the sum before the existing values, the length or tail function or avoided, but even with reordering, its faster (Fibonacci[length(Fibonacci):1]) Best regards Bart -- View this message in context: http://r.789695.n4.nabble.com/Fibonacci-tp3462636p3463050.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] R(D)COM through network
Hi, I have written a script which read in a data file, process the data, and then makup a report with the aid of the R2wd package. This works pretty well on my machine, but instead of installing R and R(D)COM on every computer in our network, I was thinking about installing the programs on 1 unused PC, and running the script on that PC. Is it possible to make a call to that PC, run the program, and get back a word document? Here an example script (taken from the R2wd package): wdGet() wdTitle("R2wd, A Package for writing Word Documents from R",label="R2wd") wdSection("Introduction") wdBody("This is an example on how to use the R2wd package.") wdSave("MyDoc") wdQuit() I'm now already using RScript with a few parameters to read in the right datafile. And I'm using Windows XP on my PC Thanks for your time Bart -- View this message in context: http://r.789695.n4.nabble.com/R-D-COM-through-network-tp3399868p3399868.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] Why my package is not being generated?
a typo in r-projeCt.org? install.packages("tests",repos="http://r-forge.r-project.org";) -- View this message in context: http://r.789695.n4.nabble.com/Why-my-package-is-not-being-generated-tp3255111p3258202.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] problem with D(COM) Server
I have the problem with the basic test too. But I installed D(COM) for use with the R2wd package. Despite the problem with the basic test, R2wd works like a charm. So just try your code, it actually might work fine. Bart -- View this message in context: http://r.789695.n4.nabble.com/problem-with-D-COM-Server-tp3006087p3257688.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] Counter in a For Loop - Efficiency Issue
without a reproducible sample, it is hard to tell, but I will give it a shot. Maybe it's possible to merge your M with M2: merge(M, M2) If you only want to count times, you can use seq_along(x) in a by function eg: dat <- data.frame(person=rep(c(1,2,3), each=5), time=rnorm(15)) by(dat$person, dat$person, function(x) seq_along(x)) Ofcourse you can use any of the other vectorisation functions (lapply, apply, aggregate, ) HTH Bart -- View this message in context: http://r.789695.n4.nabble.com/Counter-in-a-For-Loop-Efficiency-Issue-tp3253674p3253698.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] Need help with my homework
I think you focussed on the wrong post. You are discussing with Josh, but others already mentioned a good solution:"ask google". It took me less than a minute to find a function which makes a random walk and plot the path. So if you are out there to study such code, go search for it, and if you don't get it, post the code here you don't understand and ask specific. Also, asking for giving some code without proving your tried it on yourself, isn't a good way to ask here. Why don't you give it a try yourself, and if you are stuck, come back, post your code and explain what doesn't work. I'm sure there are people who will help you if they can. good luck Bart -- View this message in context: http://r.789695.n4.nabble.com/Need-help-with-my-homework-tp3238794p3241802.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] Problem reading PostgreSQL data with RODBC
I think this is a problem with quotes. If you look good, you see: seiz.df <- sqlFetch(chnl, 'source.MAIN') ... 'source.main': table not found on channel You asked "MAIN", but your db can't find "main". If you use seiz.df <- sqlFetch(chnl, '\"source\".\"MAIN\"') , you problem should be gone. Bart -- View this message in context: http://r.789695.n4.nabble.com/Problem-reading-PostgreSQL-data-with-RODBC-tp3232706p3233977.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] Selecting the first occurrence of a value after an occurrence of a different value
Ofcourse you can loop over your data, but a vectorised way: f.search <- function(x, ref, search) { cs <- match(cumsum(x==ref), cumsum(x==ref)) outp <- suppressWarnings(tapply(x==search,cs, function(x) min(which(x==1 outp <- outp[outp!=Inf] # To remove the occurences where nothing was found return(as.vector(as.numeric(names(outp))+outp - 1)) } f.search(x, "MagDwn", "Resp") Good luck Bart -- View this message in context: http://r.789695.n4.nabble.com/Selecting-the-first-occurrence-of-a-value-after-an-occurrence-of-a-different-value-tp3217340p3217482.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] extracting more information from optim in R?
I have no experience with writing C code, but if I have such problems in R code, I add a line to my function which prints the values to the console: eg: fr <- function(x) { ## Rosenbrock Banana function x1 <- x[1] x2 <- x[2] cat (paste(x1, x2, "\n")) 100 * (x2 - x1 * x1)^2 + (1 - x1)^2 } optim(c(-1.2,1), fr) If the same goes for C, I don't know. Bart -- View this message in context: http://r.789695.n4.nabble.com/extracting-more-information-from-optim-in-R-tp3213439p3214066.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] Extract table from a webpage
Maybe you should take a look at the view all button. >From there you can guess the next link: http://www.etintelligence.com/etig/et500/et500Ranking.jsp?param=1&msg=1&year=2010&rslt=500 this should give you the whole list Bart -- View this message in context: http://r.789695.n4.nabble.com/Extract-table-from-a-webpage-tp3013098p3013262.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] Regular expression to find value between brackets
Hi, this should be an easy one, but I can't figure it out. I have a vector of tests, with their units between brackets (if they have units). eg tests <- c("pH", "Assay (%)", "Impurity A(%)", "content (mg/ml)") Now I would like to hava a function where I use a test as input, and which returns the units like: f <- function (x) sub("\\)", "", sub("\\(", "",sub("[[:alnum:]]+","",x))) this should give "", "%", "%", "mg/ml", but it doesn't do the job quit well. After searching in the manual, and on the help lists, I cant find the answer. anyone? Bart -- View this message in context: http://r.789695.n4.nabble.com/Regular-expression-to-find-value-between-brackets-tp2994166p2994166.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] applying strsplit to a whole column
Maybe I'm completely wrong, but I get sometimes names like X..123 when I import data through read.delim, read.table, ... When it's necessary I avoid the X..123 by adding read.delim(xxx, check.names=F) HTH Bart -- View this message in context: http://r.789695.n4.nabble.com/applying-strsplit-to-a-whole-column-tp2313915p2314619.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] SQL/R
see the manual from package sqldf: http://cran.r-project.org/web/packages/sqldf/sqldf.pdf Bart -- View this message in context: http://r.789695.n4.nabble.com/SQL-R-tp2298545p2301975.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] Access web content from within R
Thanks Henrique, that does the trick!!! Bart -- View this message in context: http://r.789695.n4.nabble.com/Access-web-content-from-within-R-tp2289953p2292181.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] Access web content from within R
Marsh, you are absolutely right, I forget the link to the db. Actually its a webpage for each monograph number: http://extranet.pheur.org/4DLink1/4DCGI/Web_View/mono/198 http://extranet.pheur.org/4DLink1/4DCGI/Web_View/mono/731 ... As I have a list with the numbers of interest (l<- c(198, 731,355)), I can paste the webadress together with the numbers, but then I need to substract the COS info. Kind regards Bart -- View this message in context: http://r.789695.n4.nabble.com/Access-web-content-from-within-R-tp2289953p2291839.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] Access web content from within R
Hi, I have to search in an online db for registered manufacturers of raw materials. Can I use R for the following: I have a list with monograph numbers eg: l <- c(198, 731,355) Now I want to make a dataframe, containing the monograph number and the information listed under COS: Certificate holder, certificate number, Status, Type Is this possible with R? kind regards Bart -- View this message in context: http://r.789695.n4.nabble.com/Access-web-content-from-within-R-tp2289953p2289953.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] RODBC in R
As Marc already pointed out, you masked your pwd with , but you didn't correctly used the arguments. "your ODBC connection" is the name of your ODBC connection you setup in your environment. Like "postgresql35W" or something I can't write out a complete syntax when I don't know your actual ODBC name. Bart -- View this message in context: http://r.789695.n4.nabble.com/RODBC-in-R-tp2258510p2259213.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] Optimization problem
How about smoothing the percentages, and then take the second derrivative to find the inflection point? which.max(diff(diff((lowess(percentages)$y Bart -- View this message in context: http://r.789695.n4.nabble.com/Optimization-problem-tp2258654p2258828.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] RODBC in R
Hi, case should be tolower, toupper, nochange, not "*" . I think you switched case for pwd? Anyway, you can just use odbConnect("yourODBC connection") to connect to your ODBC db. Bart -- View this message in context: http://r.789695.n4.nabble.com/RODBC-in-R-tp2258510p2258742.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] Help with seting up comparison
Greg, the animals are a sample of a larger population, as you guessed. I used lmer to estimate the effects: > lmer(Count~Animal | Day, dat) Linear mixed model fit by REML Formula: Count ~ Animal | Day Data: dat AIC BIC logLik deviance REMLdev 1554 1574 -772 15421544 Random effects: Groups NameVariance Std.Dev. Corr Day (Intercept) 1.7707e-02 0.1330678 Animal 4.0287e-05 0.0063472 1.000 Residual 2.0917e+00 1.4462790 Number of obs: 430, groups: Day, 4 Fixed effects: Estimate Std. Error t value (Intercept) 4.2423 0.1257 33.76 But how does this help me to state that there is no effect within an animal? anova doesn't seems to work (gives an empty table) I'm sorry, but I have no experience with lme models, only lm. Thanks for your time Bart > From: greg.s...@imail.org > To: bartjoo...@hotmail.com; r-help@r-project.org > Date: Mon, 7 Jun 2010 14:54:47 -0600 > Subject: RE: [R] Help with seting up comparison > > Are you interested in only those 35 animals (not every going to look at any > other animals other than those 35, but you want to predict what will happen > for those 35)? Or are the 35 animals a sample of a larger population of > animals? > > If the later (seems the most likely case) then you probably want to use a > mixed effects model (nlme or lme4 packages) with animal as a random effect, > then just look at the fixed effect of day. > > Hope this helps, > > -- > Gregory (Greg) L. Snow Ph.D. > Statistical Data Center > Intermountain Healthcare > greg.s...@imail.org > 801.408.8111 > > > > -Original Message- > > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r- > > project.org] On Behalf Of Bart Joosen > > Sent: Monday, June 07, 2010 9:14 AM > > To: r-help@r-project.org > > Subject: [R] Help with seting up comparison > > > > > > Hi, > > > > I tried on this, but couldn't figure it out: > > Suppose I have a dataframe as follows: > > dat <- data.frame(Day=rep(rep(c(1,2), each=4),2), Animal = rep(c(1,2), > > each=8), Count=c(rnorm(8, 100), rnorm(8,90))) > > > > 2 animals are being examined on 2 different days. Count is the result. > > > > Now I need to point out whether or not there is a difference between > > the > > days. > > I did this by an ANOVA test, while first converting the animal and day > > to a > > factor variable: > > dat$Animal <- as.factor(dat$Animal) > > dat$Day <- as.factor(dat$Day) > > mod <- lm(Count ~Animal * Day,dat) > > anova(mod) > > > > Now I have to check for difference within the animal, to see if there > > is a > > difference in count for each day. (In my real data, I have 35 animals, > > with > > 4 days, and 4 results). > > I thought about a Tukey HSD test, but this compares every day of every > > animal with every other day of every other animal. (TukeyHSD(aov(mod))) > > > > Any idea about which function (or model for lm) to use to only compare > > days > > within every animal? > > > > Best regards > > > > Bart > > > > > > -- > > View this message in context: http://r.789695.n4.nabble.com/Help-with- > > seting-up-comparison-tp2246106p2246106.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. _ Hotmail: betrouwbare e-mail met krachtige spambescherming. [[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 with seting up comparison
Hi, I tried on this, but couldn't figure it out: Suppose I have a dataframe as follows: dat <- data.frame(Day=rep(rep(c(1,2), each=4),2), Animal = rep(c(1,2), each=8), Count=c(rnorm(8, 100), rnorm(8,90))) 2 animals are being examined on 2 different days. Count is the result. Now I need to point out whether or not there is a difference between the days. I did this by an ANOVA test, while first converting the animal and day to a factor variable: dat$Animal <- as.factor(dat$Animal) dat$Day <- as.factor(dat$Day) mod <- lm(Count ~Animal * Day,dat) anova(mod) Now I have to check for difference within the animal, to see if there is a difference in count for each day. (In my real data, I have 35 animals, with 4 days, and 4 results). I thought about a Tukey HSD test, but this compares every day of every animal with every other day of every other animal. (TukeyHSD(aov(mod))) Any idea about which function (or model for lm) to use to only compare days within every animal? Best regards Bart -- View this message in context: http://r.789695.n4.nabble.com/Help-with-seting-up-comparison-tp2246106p2246106.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] Create counter variable for subsets without a loop
Solved it another way, without apply: data2 <- data[order(data$state.region,-data$Population),] cx <- as.numeric(data2$state.region) data2$rank <- cumsum(rep(1,length(cx)))-match(cx,cx) + 1 all.equal(data2==data) Bart -- View this message in context: http://r.789695.n4.nabble.com/Create-counter-variable-for-subsets-without-a-loop-tp2220663p2221052.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] Create counter variable for subsets without a loop
take a look at the by, ave, aggregate and apply functions, perhaps one suits your needs Bart -- View this message in context: http://r.789695.n4.nabble.com/Create-counter-variable-for-subsets-without-a-loop-tp2220663p2220925.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] How to replace all values in a data.frame with another ( not 0) value
try x[is.na(x)] <- "000/000" Bart -- View this message in context: http://r.789695.n4.nabble.com/How-to-replace-all-NA-values-in-a-data-frame-with-another-not-0-value-tp2125458p2125509.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] RODBC looping sql script
Hi, You should use the paste command: for (i in 1:length(vessel[,1])) { query<-paste("Select * From vessel Where common.utility(", vessel[i,1],", ", ,vesselyear[i,2], ")", sep="") final<-sqlQuery(channel,paste(query)) } Bart Jason Gasper wrote: > > Dear R users, > > I am querying an Oracle database using sqlQuery() from the RODBC > package. What I would like to do is embed my R Sql query in a for loop. > For example > suppose the data.frame "vessel" contains two columns: vessel[,1]= vessel > id and vessel[,2]=permit year > > I am using "vessel" as an input in a SQL based function that require > inputs of permit year and vessel id as described below: > > query<-"Select * From vessel Where common.utility(vessel ID,vessel year)" > > final<-sqlQuery(channel,paste(query)) > > Now suppose I want to loop through my vessel table such that the vessel > ID and vessel year corresponds with i: > > for (i in 1:length(vessel[,1])) { > query<-"Select * From vessel Where common.utility(vessel[i,1],vessel > year[i,2])" > " > final<-sqlQuery(channel,paste(query)) > > } > Ignoring the fact I didn't include code to create and ever expanding > final table for loop, does anyone know how to index inside the Where > clause of a sql statement (i.e., common.utility(vessel[i,1],vessel > year[i,2])? > > > > > > -- > Jason Gasper > National Marine Fisheries Service > Alaska Region, Sustainable Fisheries Division > 709 W. 9th St. Juneau, Alaska 99801 > Juneau, Alaska 99801 > > Phone 907-586-7237 > Fax 907-586-7249 > > __ > 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. > > -- View this message in context: http://n4.nabble.com/RODBC-looping-sql-script-tp1570038p1570237.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] TukeyHSD troubles
treat_code isn't a factor, but a numeric variable. You should use: summary(aov(EtoH~as.factor(treat_code), mydata)) TukeyHSD(aov(EtoH~as.factor(treat_code), mydata)) Bart -- View this message in context: http://n4.nabble.com/TukeyHSD-troubles-tp1570205p1570228.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] forecasted Results
How on earth can you forecast your Revenue with such a small sample??? And how do you wanna forecast, how do you want to report, which graphs do you want to make, You started out 4 threads, in each threads was asked to RTFM, provide examples, clarify, . But you still give unclear, hazy answers, and even more questions I give up (But you could take a look at R2HMTL, R2wd, ) Good luck Bart -- View this message in context: http://n4.nabble.com/Generating-reports-from-database-tp1564238p1565785.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] Thanks Friends
Chinna, glad to hear that you are connected to your db. About your reports: we don't know what you are looking for, so how on earth can we help you. As already pointed out: List Requirements: " PLEASE do read the posting guide [1]http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. " So please specify your problem, provide some example data, ... This example data hasn't to be real data, but it should be reflecting your real data. eg data.frame(ID=seq(1:10), result=rnorm(10)) Bart -- View this message in context: http://n4.nabble.com/Generating-reports-from-database-tp1564238p1565547.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] Generating reports from database
Chinna, I found that there are ODBC drivers for the teradatabase available, so with the use of RODBC you should be able to connect to your database. This will allow you to extract your data into an R dataframe, and make reports of it. But you noticed in another thread that you are an R beginner, so maybe you should sit down and take the time to learn how to work with R, read the manuals and docs! R is very powerfull and flexible, but is known for it's rather steep learning curve. And connecting to a db, extracting the data you want, analyse this and put in a report, with graphs isn't that hard, but if you are starting out, you have to accept that you will have to learn the basics. So go on, play with R and your data, and ask when you are stuck and can't figure it out without reading the manuals, help lists, ... Bart -- View this message in context: http://n4.nabble.com/Generating-reports-from-database-tp1564238p1564443.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] sql query variable
Another way: cat("Station number?") flush.console() sn <- scan(quiet=TRUE,n=1) sqlQuery(conn, paste("select to_char(lsd,'-mm') as yr,ttl_mo_prcp from mo_rains where stn_num=",sn,sep="")) Bart -- View this message in context: http://n4.nabble.com/sql-query-variable-tp1558189p1558504.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] R2HTML
Hi, Perhaps you could do HTML(summary(iris)) ? Bart -- View this message in context: http://n4.nabble.com/R2HTML-tp1475505p1475547.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] problems with SPC charts in R
It looks like there is an NA created, and then used to calculate stdev. But it's inside function, and these seems all wrapped functions, where one function calls another, which calls another, which calls . I suggest you contact the maintainer of the package, send him the data and your error. To find his e-mail address see ?qcc. (If you solved your problem, please let us know) Bart -- View this message in context: http://n4.nabble.com/problems-with-SPC-charts-in-R-tp1467901p1471287.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] problems with SPC charts in R
I'm sorry, I'm doing this in my spare time, hadn't time during the day. But I tried your example, and didn't get the error. If you get the error with your example (with the data you had sent to this list), then I think Peter is right, and it has something to do with margins you had set. Try to start a new R session, don't set your margins for new plots, and try if this works. Bart -- View this message in context: http://n4.nabble.com/problems-with-SPC-charts-in-R-tp1467901p1469147.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] problems with SPC charts in R
I'm sorry, I'm doing this in my spare time, hadn't time during the day. But I tried your example, and didn't get the error. If you get the error with your example (with the data you had sent to this list), then I think Peter is right, and it has something to do with margins you had set. Try to start a new R session, don't set your margins for new plots, and try if this works. Bart -- View this message in context: http://n4.nabble.com/problems-with-SPC-charts-in-R-tp1467901p1469138.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] problems with SPC charts in R
Please add an reproducible example, so that we can see where it goes wrong. Maybe the error is raised by faulted data? Bart -- View this message in context: http://n4.nabble.com/problems-with-SPC-charts-in-R-tp1467901p1468441.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] sqlUpdate RODBC
You solved your date column problem? You should make a table with a date column. Instead of adjusting the date setting for this session, you can use the format function of R to adjust the string you are feeding to your db? Bart -- View this message in context: http://n4.nabble.com/sqlUpdate-RODBC-tp1460867p1461613.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] format
maybe you are looking for: format(x,drop0trailing=TRUE) Bart -- View this message in context: http://n4.nabble.com/format-tp1457899p1457952.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] format
how about round? ?round -- View this message in context: http://n4.nabble.com/format-tp1457899p1457938.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] Solving an optimization problem: selecting an "optimal" subset
Here some kind of a brute force attack: #brute force solution, only working with relative small subsets: n <- 200 elem <- 3 target <- 200 x <- rnorm(n,100,10) x.combinations <- combn(x,elem) sums <- apply(x.combinations,2,function(x) (sum(x)-target)^2) ans <- (x.combinations[,which.min(sums)]) #seems to work for larger subsets: require(gtools) x.combinations <- combinations(n, elem) sums <- apply(x.combinations,1,function(sel) (sum(x[sel])-target)^2) print(x[x.combinations[which.min(sums),]]) Although it takes a lot of computation time, you are sure you will find the minimum. Bart -- View this message in context: http://n4.nabble.com/Solving-an-optimization-problem-selecting-an-optimal-subset-tp1446084p1457514.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] Solving an optimization problem: selecting an "optimal" subset
Could you please specifiy your problem, if possible with some data? Is it a subset of a vector containing 100 elements, or 1ths? A random number of elements that should be chosen, or the best 10 values which sums up to a defined value? Bart -- View this message in context: http://n4.nabble.com/Solving-an-optimization-problem-selecting-an-optimal-subset-tp1446084p1457323.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] Merge: sort=F not preserving order?
You could add an extra sequence on the dataframe you wish to sort on. Merge together, sort by the sequence, delete the sequence. It's a bit more work, but it will give you what you want. Bart -- View this message in context: http://n4.nabble.com/Merge-sort-F-not-preserving-order-tp1312234p1340790.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] Sampling from a Postgres database
One way could be to first select only the unique ID's, sample this and then select only the relevant records: strQuery = "SELECT ID from tblFoo;" IDs <- sqlQuery(channel, strQuery) sample.IDs <- sample(IDs,10) strQuery = paste("SELECT ID from tblFoo WHRE ID IN(", sample.IDs, ");") IDs <- sqlQuery(channel, strQuery) Bart christiaan pauw-2 wrote: > > Hi Everybody > > Is there a way in which one can use the RPostgreSQL package to take a > sample > from a table in Postgres database without having to read the whole table > into R > > regards > Christiaan > > [[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. > > -- View this message in context: http://n4.nabble.com/Sampling-from-a-Postgres-database-tp1014506p1014638.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] Automatic task planner
Hi, I'm making a database for my company, and I would like to automate some tasks. One of the tasks that is demanding a lot of time is making up the task schedule. I'm wondering if it's possible to automate this, and how this can be done. As the database is made up in postgresql, I can access my data from R. Below you will find some example data. Product: Which product? Batch: Which batch of the product? Date in: Date when the samples arrive Date out: Deadline date when the samples should be analysed Analysis: Which method should be used? Startup cost: cost to setup the analysis Sup cost: supplementary cost per sample after the analysis has been setuped. So if you take a look at the data, Product A, batch 1 and 2 can be analysed together with product B batch 1 and 2 for analysis A, to reduce the costs (startup cost counts only once). Product A batch 3 arrives too late to go for one time analysis A. Any ideas about how this can be done? Thanks for your time Bart Sample data: dat <- structure(list(Product = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor"), Batch = c(1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L), Date.in = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("10/05/09", "11/05/09", "18/05/2009" ), class = "factor"), Date.out = structure(c(1L, 1L, 2L, 2L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L), .Label = c("15/05/09", "16/05/09", "23/05/09"), class = "factor"), Analysis = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 3L, 4L, 1L, 3L, 4L), .Label = c("A", "B", "C", "D"), class = "factor"), Startup_cost = c(100L, 120L, 100L, 120L, 100L, 120L, 100L, 50L, 60L, 100L, 50L, 60L), Sup_cost = c(10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L)), .Names = c("Product", "Batch", "Date.in", "Date.out", "Analysis", "Startup_cost", "Sup_cost"), class = "data.frame", row.names = c(NA, -12L)) [[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] count the cumulative for each subject
Peter, I actually took a look at the ave function, but couldn't manage to get it right. But when I try your code, I get "Error in as.vector(x, mode) : invalid argument 'mode'". Any ideas? Bart - Original Message - From: "Peter Dalgaard" <[EMAIL PROTECTED]> To: "bartjoosen" <[EMAIL PROTECTED]> Cc: Sent: Monday, November 24, 2008 3:42 PM Subject: Re: [R] count the cumulative for each subject bartjoosen wrote: How about: tapply(dat$x1,dat$subject,function(x) cumsum(x)) which gives you a list for each subject. this can be converted to a vector: do.call("c",tapply(dat$x1,dat$subject,function(x) cumsum(x))) So if your data frame is ordered for your subjects: cbind(your.data.frame,do.call("c",tapply(dat$x1,dat$subject,function(x) cumsum(x Sounds like a job for the eternally overlookked ave() function: with(dat, ave(x1, subject, cumsum)) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] count the cumulative for each subject
Peter, After I made a small modification it worked: with(dat, ave(x1, subject, FUN=cumsum)) But what's the use of with? If I use ave(x1, subject, FUN=cumsum), I get the same result? Bart - Original Message - From: "Bart Joosen" <[EMAIL PROTECTED]> To: "Peter Dalgaard" <[EMAIL PROTECTED]> Cc: Sent: Monday, November 24, 2008 7:29 PM Subject: Re: [R] count the cumulative for each subject Peter, I actually took a look at the ave function, but couldn't manage to get it right. But when I try your code, I get "Error in as.vector(x, mode) : invalid argument 'mode'". Any ideas? Bart - Original Message - From: "Peter Dalgaard" <[EMAIL PROTECTED]> To: "bartjoosen" <[EMAIL PROTECTED]> Cc: Sent: Monday, November 24, 2008 3:42 PM Subject: Re: [R] count the cumulative for each subject bartjoosen wrote: How about: tapply(dat$x1,dat$subject,function(x) cumsum(x)) which gives you a list for each subject. this can be converted to a vector: do.call("c",tapply(dat$x1,dat$subject,function(x) cumsum(x))) So if your data frame is ordered for your subjects: cbind(your.data.frame,do.call("c",tapply(dat$x1,dat$subject,function(x) cumsum(x Sounds like a job for the eternally overlookked ave() function: with(dat, ave(x1, subject, cumsum)) -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] alternative to multiple t-test to find steady-state
Hi, My collegue has asked me to calculate the steady state of a pharmacokinetic study. This is defined as where the concentration after a certain time doesn't increase anymore. So if I perform multiple t-tests between the sample points, with alternative less, then I can see which from which time point there isn't an increase in concentration. But this doesn't feel good to me. I don't think that this is the right way to check if the concentration is still increasing. And if I perform multiple comparisons, I should use the bonferroni correction? I was thinking about an ANOVA test to find differences between the time points, but as there are no replications and it's a paired t-test, I'm not able to calculate an ANOVA. Below you find the data, I hope someone can point me to the right way. Kind regards Bart dat <-structure(list(Sample = 1:8, X12 = c(0.305, 0.44, 0.6, 0.47, 0.49, 0.17, 0.435, 0.435), X36 = c(0.84, 1.16, 1.32, 1.17, 0.78, 0.43, 0.93, 0.9), X60 = c(1.05, 0.9, 0.98, 1.03, 0.77, 0.47, 0.85, 1.11), X84 = c(0.87, 0.95, 1.31, 1.13, 0.62, 0.93, 1.02, 0.79), X108 = c(0.79, 0.92, 1.29, 0.97, 0.74, 0.86, 1.03, 1.41)), .Names = c("Sample", "X12", "X36", "X60", "X84", "X108"), class = "data.frame", row.names = c(NA, -8L)) for (i in 2:5) { print(paste((names(dat)[c(i,i+1)]),collapse="-")) print(t.test(x=dat[,i],y=dat[,i+1],alternative="less",paired=T,conf.level=0.95))} _ [[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] AUC steady state calculations
Hi, a collegue has send me an excel sheet with some plasma values, and now he wants to know the AUC steady state. I took a look at the CRAN taskviews, and came up with PK, PKtools, ... The AUC calculation, no problem with that, but how do I calculate the steady state? One way of thinking was with the aid of multiple t-test, to find where we couldn't find difference between the different measuring points, and take this as steady state, but I'm not sure that this is the right way. As I'm not home in the pharmacokinetic world, I was hoping someone with some more experience can shed some light on this (altough for me) dark material. Kind Regards Bart PS: Here some example data: dat<- structure(list(Sample = c(1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), tijd = c(12L, 36L, 60L, 84L, 108L, 132L, 12L, 36L, 60L, 84L, 108L, 132L), conc = c(0.621518061431366, 0.87531564366726, 0.916311538568891, 0.880947260781843, 0.852202744098934, 0.218909173985895, 1.22305496551836, 1.30075841227452, 0.995918019674464, 1.33214099618361, 1.42613784296527, 0.290928921761672)), .Names = c("Sample", "Time", "conc"), row.names = c(NA, -12L), class = "data.frame") [[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] export R-data to VisIt
Thanks Katharine, for the moment I'm not on a PC on which VisIt is installed, but it should do the trick. By the way: to use 2 variables when creating the cdf file: ncnew <- create.ncdf(filename="file.cdf", vars = list(x1,x2)) That was one of the things that was working within the 2 hours ;-). Thanks to Katharine and Peter for your time Bart - Original Message - From: "Katharine Mullen" <[EMAIL PROTECTED]> To: "Bart Joosen" <[EMAIL PROTECTED]> Cc: "Peter Dalgaard" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Friday, October 19, 2007 6:27 PM Subject: Re: [R] export R-data to VisIt Below is an example R -> netCDF -> R for rows of a dataframe that are numeric vectors --note however that your dataframe includes character vectors. I can't look into that case at the moment - maybe it's easy to solve, or maybe you have to do some hashing. ## begin ex. library(ncdf) dat <- matrix(rnorm(20),10,2) c1 <- dim.def.ncdf( "c1", "c1units", 1:nrow(dat) ) c2 <- dim.def.ncdf( "c2", "c2units", 1:nrow(dat) ) x1 <- var.def.ncdf(name="v1", units="c1units",dim = c1, missval=0) x2 <- var.def.ncdf(name="v2", units="c2units",dim = c2, missval=0) ## for some reason, when vars is the vector c(x1,x2) this does't work ## it may be a bug; get around my adding other vars later ncnew <- create.ncdf(filename="file.cdf", vars = x1) ncnew <- var.add.ncdf(ncnew, x2) put.var.ncdf(ncnew, "v1", dat[,1]) put.var.ncdf(ncnew, "v2", dat[,2]) close.ncdf(ncnew) ofile <- open.ncdf("file.cdf") c_x1 <- get.var.ncdf(ofile, "v1") c_x2 <- get.var.ncdf(ofile, "v2") > Peter, what a quick response! But unfortunately, yes I tried the ncdf package, I looked at the examples, but after 2 hours trying and many, many errors, I gave up. Bart - Original Message - From: "Peter Dalgaard" <[EMAIL PROTECTED]> To: "Bart Joosen" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Friday, October 19, 2007 4:56 PM Subject: Re: [R] export R-data to VisIt Bart Joosen wrote: > Hello, > > Is there anyone porting R data to VisIt (http://www.llnl.gov/visit/)? > Altough VisIt accepts 5 dozen of data formats, I can't get my data into > VisIt. > > I currently ran a simulation which gave me a data frame, which I wanted to > import into VisIt to further explore the dataframe. > > Let's say I have a data frame as follows: > > dat <- data.frame(cbind( 1, 1:10),X3= sample(LETTERS[1:3], 10, > repl=TRUE)) > > My currently data export is write.table(dat,"C:/filename.csv") > But I can't import this kind of data in Visit. > An option is to export my dataframe as a .CDF file, but I couldn't get the > right output of my dataframe with netcdf. > > So how do I put my dataframe in a netCDF format, or is there anyone who > knows the easiest way to transport my data to VisIt? > > Have you tried the ncdf package? -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ R-help@r-project.org mailing list 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] export R-data to VisIt
Peter, what a quick response! But unfortunately, yes I tried the ncdf package, I looked at the examples, but after 2 hours trying and many, many errors, I gave up. Bart - Original Message - From: "Peter Dalgaard" <[EMAIL PROTECTED]> To: "Bart Joosen" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Sent: Friday, October 19, 2007 4:56 PM Subject: Re: [R] export R-data to VisIt Bart Joosen wrote: > Hello, > > Is there anyone porting R data to VisIt (http://www.llnl.gov/visit/)? > Altough VisIt accepts 5 dozen of data formats, I can't get my data into > VisIt. > > I currently ran a simulation which gave me a data frame, which I wanted to > import into VisIt to further explore the dataframe. > > Let's say I have a data frame as follows: > > dat <- data.frame(cbind( 1, 1:10),X3= sample(LETTERS[1:3], 10, > repl=TRUE)) > > My currently data export is write.table(dat,"C:/filename.csv") > But I can't import this kind of data in Visit. > An option is to export my dataframe as a .CDF file, but I couldn't get the > right output of my dataframe with netcdf. > > So how do I put my dataframe in a netCDF format, or is there anyone who > knows the easiest way to transport my data to VisIt? > > Have you tried the ncdf package? -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] export R-data to VisIt
Hello, Is there anyone porting R data to VisIt (http://www.llnl.gov/visit/)? Altough VisIt accepts 5 dozen of data formats, I can't get my data into VisIt. I currently ran a simulation which gave me a data frame, which I wanted to import into VisIt to further explore the dataframe. Let's say I have a data frame as follows: dat <- data.frame(cbind( 1, 1:10),X3= sample(LETTERS[1:3], 10, repl=TRUE)) My currently data export is write.table(dat,"C:/filename.csv") But I can't import this kind of data in Visit. An option is to export my dataframe as a .CDF file, but I couldn't get the right output of my dataframe with netcdf. So how do I put my dataframe in a netCDF format, or is there anyone who knows the easiest way to transport my data to VisIt? Kind Regards Bart [[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.