Re: [R] aggregate binary response data
?tapply - cuncta stricte discussurus - -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Graham Leask Sent: Thursday, December 24, 2009 7:57 AM To: r-help@r-project.org Subject: [R] aggregate binary response data Dear list I have a response variable coded 0/1 i.e. a binary response. There are 20,000 individual responses that I would like to aggregate into numbers of each category (i.e. 0/1) by group called dn (350 different groups) and by month mth (there are several hundred responses per month. What is the simplest way to perform this operation in 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. __ 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 in merging
Not sure if its guaranteed but this sqlite join does seem to preserve the order of the first data frame. > library(sqldf) > BOD Time demand 118.3 22 10.3 33 19.0 44 16.0 55 15.6 67 19.8 > BODrev <- BOD[6:1,]; BODrev Time demand 67 19.8 55 15.6 44 16.0 33 19.0 22 10.3 118.3 > sqldf("select * from BODrev, BOD using(Time)") Time demand demand 17 19.8 19.8 25 15.6 15.6 34 16.0 16.0 43 19.0 19.0 52 10.3 10.3 618.38.3 See home page at: http://sqldf.googlecode.com On Thu, Dec 24, 2009 at 2:26 PM, wrote: > > Hi All, > I want to "merge" two datasets by column "ID" and I don't want the result to > be sorted by "ID". I am doing the following: > > z = merge(x, y, by = "ID", sort=F) > The result is not sorted by "ID". But (as oppose to what I expected) it is > not even in the original order of either "x" or "y". > Can somebody tell what to do if I wanted it to be in the original order of > x. > > P.S.: As my dataset is very huge and I couldn't find the right subset of the > data which explains the above problem, so I can't attach it at the moment. > If anybody knows the answer, please reply; or else I will try to get the > right subset. > > Thanks in advance > > Utkarsh > __ > 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] boot() with an array-valued statistic?
Dear guRus, is there a version of boot() that deals with array data and array-valued statistics? For example: foo <- array(rnorm(120),dim=c(3,5,8)) means <- apply(foo, MARGIN=c(2,3), FUN=mean) means contains the means over the first dimension of foo: a 5x8 array. Now I would like to bootstrap this array, perhaps with something along the lines of some array.boot(), with an additional MARGIN parameter: means.boot <- array.boot(foo, statistic=mean, MARGIN=c(2,3), R=1000) I would like means.boot to contain (e.g., in analogy to boot(), in a component $t) an array of dimensions 1000x5x8, containing componentwise means of sampled slices of foo, e.g., to get confidence intervals like this: apply(means.boot$t,MARGIN=c(2,3),FUN=quantile,probs=c(.975,.025)) I have been playing around with plyr and various flavors of apply, and searching only yielded lots of hits for boot.array(), which is something completely different... Any help would be greatly appreciated! Cheers Stephan __ 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 SVM package Kernlab
Hi, I seem to have made some headway on this problem but its still not solved. It seems like this is a "factor" issue. When I read my training set, I read it with read.csv() which converts each of the columns as "factors". From this if I take a single row as my testSeq, it works great. On the other hand, when I read in my test sequence from a Fasta file, I am using the "seqinr" package's function "readFasta()" or if read a sequence directly from a file I am using "scan()": eg: train500 = read.csv("toClassify500_1.csv",header=TRUE) # reading the training set modelforSVM <- ksvm(Class ~ ., data = train500, kernel = "rbfdot", kpar = "automatic", C = 60, cross = 3, prob.model = TRUE) Now if I do: tindex =sample(1:dim(train500)[1], 1) testSeq=train500[tindex,] predict(modelforSVM, testSeq); It works great. BUT if I do: my.file=file("chr4_seqs.fasta", open="r") chr4Seq = scan(my.file,list("",""),nlines=2) # read the data from a fasta file using scan() seqId = chr4Seq[[1]]; testSeq = as.data.frame(t(s2c(toupper(chr4Seq[[2]] # the s2c function just converts the "STRING" to char vector "S" "T" "R" "I" "N" "G" predict(modelforSVM, testSeq); Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : contrasts can be applied only to factors with 2 or more levels - If I apply factor() to testSeq, it still doesn't work : eg: testSeq=data.frame(lapply(testSeq,factor)) I still get Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : contrasts can be applied only to factors with 2 or more levels Another thing I tried was reading the fasta file using the readFasta() function and taking a sample input from the training set itself: data500_1_fasta = read.fasta("toClassify500.fasta") # read a fasta file via the seqinr package data500_1_seq = t(getSequence(data500_1_fasta)) # get the sequences from it, 256 sequences, first 128 are +, next 128 are - data500_1_df = as.data.frame(data500_1_seq) #make a data frame from it class = append(rep("+",times=128),rep("-",times=128)) # add the class column to it data500_1_df = cbind(Class=class,data500_1_df) data500_1_df = data.frame(lapply(data500_1_df,factor)) #finally apply the factor() on the data frame #Now train and get the model modelforSVM <- ksvm(Class ~ ., data = data500_1_df, kernel = "rbfdot", kpar = "automatic", C = 60, cross = 3, prob.model = TRUE) and finally: tindex =sample(1:dim(data500_1_df)[1], 1) testSeq=data500_1_df[tindex,] predict(modelforSVM, testSeq); Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : contrasts can be applied only to factors with 2 or more levels I am very confused at this point. What am I doing wrong? How do I use the factor() function properly so that I don't get this error? Am I in the right direction at all? Thanks in anticipation of your help. -vishal [[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 dbReadTable() only a limited number of rows? (RMySQL)
Try this >drv <- dbDriver("MySQL") >con(drv, etc parameters...) > dbGetQuery(con, "select * from tableyoulike limit N_integer_first_records") Hope it helps Caveman On Fri, Dec 25, 2009 at 12:10 AM, Peng Yu wrote: > I only want to load a limited number of rows by dbReadTable(). I don't > see an option in the help. Is there an option to do so? > > __ > 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. > -- OpenSource Software Consultant CENFOSS (www.cenfoss.co.mz) SP Tech (www.sptech.co.mz) email: orvaq...@cenfoss.co.mz cell: +258828810980 __ 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 separate a data set by its factors
Thanks for the help. I tried making the pdf file as suggested. Acrobat said it was damaged and could not be opened. Is this an R bug? It did make a PostScript file that I was able to distill into PDF, but it was gray scales. How do I get the color back? And yes, I did do the layout I wanted so I could see how the days compared for each hour. On 12/24/09 4:56 PM, David Winsemius wrote: > > > pdf(test.pdf") > xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width | > Species, data = iris, scales = "free", layout = c(2, 1, 2), auto.key = > list(x = .6, y = .7, corner = c(0, 0))) > dev.off() > You may not be getting what you expect, but it may be that your plots > are all being created, but too quickly to be seen. Try printing to a > more durable "canvas". > >> And I would like to add a Poisson Distribution fit to each of these >> plots (see below), but am clueless as to how to go about it. >> >> I would like to fit a distribution to the count data for each >> combination of day and hour, and I am unable to see how to do this in a >> vector manner. For example, I tried >> density((Arrival.Val | DAY*Hour), na.rm=TRUE) >> which does not work. > > I should think the this would be informative: > > glm(Arrival.Val ~ DAY*Hour, family="poisson") > > Since DAY and Hour are factors you will get a large number of > estimates. You can use the typical regression functions, such as > predict() and summary() to get the fitted values. > I tried glm: - > glm(Arrival.Val ~ DAY*as.factor(Hour), family="poisson") Call: glm(formula = Arrival.Val ~ DAY * as.factor(Hour), family = "poisson") Coefficients: (Intercept) DAY[T.Monday] 3.15396 -0.61348 DAY[T.Saturday] DAY[T.Sunday] -0.43853 -0.93475 DAY[T.Thursday] DAY[T.Tuesday] -0.23109 -0.38137 DAY[T.Wednesday] as.factor(Hour)[T.1] -0.35715 -1.01389 as.factor(Hour)[T.2] as.factor(Hour)[T.3] -1.07451 -0.69315 as.factor(Hour)[T.4] as.factor(Hour)[T.5] -0.87384 -0.57808 as.factor(Hour)[T.6] as.factor(Hour)[T.7] -0.41122 0.26453 as.factor(Hour)[T.8] as.factor(Hour)[T.9] -0.08802 -0.01618 as.factor(Hour)[T.10] as.factor(Hour)[T.11] 0.33495 0.40389 as.factor(Hour)[T.12] as.factor(Hour)[T.13] 0.43834 0.49019 as.factor(Hour)[T.14] as.factor(Hour)[T.15] 0.56895 0.54856 as.factor(Hour)[T.16] as.factor(Hour)[T.17] 0.50895 0.49770 as.factor(Hour)[T.18] as.factor(Hour)[T.19] 0.49879 0.41296 as.factor(Hour)[T.20] as.factor(Hour)[T.21] 0.37310 0.26455 as.factor(Hour)[T.22] as.factor(Hour)[T.23] 0.14955 0.07016 DAY[T.Monday]:as.factor(Hour)[T.1] DAY[T.Saturday]:as.factor(Hour)[T.1] 1.02978 0.81973 DAY[T.Sunday]:as.factor(Hour)[T.1] DAY[T.Thursday]:as.factor(Hour)[T.1] 0.58645 0.17046 DAY[T.Tuesday]:as.factor(Hour)[T.1] DAY[T.Wednesday]:as.factor(Hour)[T.1] 0.66905 0.63300 DAY[T.Monday]:as.factor(Hour)[T.2] DAY[T.Saturday]:as.factor(Hour)[T.2] 0.61348 NA . . . . DAY[T.Tuesday]:as.factor(Hour)[T.22] DAY[T.Wednesday]:as.factor(Hour)[T.22] 0.37518 0.34362 DAY[T.Monday]:as.factor(Hour)[T.23] DAY[T.Saturday]:as.factor(Hour)[T.23] 0.52431 0.04906
Re: [R] Help with SVM package Kernlab
On Dec 25, 2009, at 1:18 AM, Vishal Thapar wrote: > Hi David, > > Thanks for your reply. The package is Kernlab. No, the package name is "kernlab". Case of characters matters in R, as the rest of your problems also illustrate as well. > I agree with you when you mention that R didn't like the structure > of the testSeq object but I can't figure out why. > > Here is the output for "dput(testSeq) and str(testSeq). Any insight > that you can see would be really helpful to me. > > Thanks, > > Vishal > > dput(testSeq) > These factors only have one level each. They need four levels. > structure(list(Class = structure(1L, .Label = "-", class = "factor"), > V1 = structure(1L, .Label = "G", class = "factor"), V2 = > structure(1L, .Label = "G", class = "factor"), > V3 = structure(1L, .Label = "A", class = "factor"), V4 = > structure(1L, .Label = "A", class = "factor"), > V5 = structure(1L, .Label = "T", class = "factor"), V6 = > structure(1L, .Label = "G", class = "factor"), snipped > > V497 = structure(1L, .Label = "G", class = "factor"), V498 = > structure(1L, .Label = "A", class = "factor"), > V499 = structure(1L, .Label = "C", class = "factor"), V500 = > structure(1L, .Label = "A", class = "factor")), .Names = c("Class", > "V1", "V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", > "V11", "V12", "V13", "V14", "V15", "V16", "V17", "V18", "V19", > "V20", "V21", "V22", "V23", "V24", "V25", "V26", "V27", "V28", > "V29", "V30", "V31", "V32", "V33", "V34", "V35", "V36", "V37", > snipped > "V493", "V494", "V495", "V496", "V497", "V498", "V499", "V500" > ), row.names = c(NA, -1L), class = "data.frame") > - > str(testSeq) > > 'data.frame': 1 obs. of 501 variables: > $ Class: Factor w/ 1 level "-": 1 > $ V1 : Factor w/ 1 level "G": 1 > $ V2 : Factor w/ 1 level "G": 1 You probably out to read your data in with stringsAsFactors=FALSE and work with the characters before converting the columns in the dataframe to factors. At the moment, I am guessing htat you read them in a single line at a time and then bound them together somehow. > > > On Fri, Dec 25, 2009 at 12:15 AM, David Winsemius > wrote: > > On Dec 24, 2009, at 11:42 PM, Vishal Thapar wrote: > > Hi useR's, > > I am resending this request since I got no response for my last post > and I > am new to the list so pardon me if I am violating the protocol. > > I am trying to use the "Kernlab" package for training and prediction > using > SVM's. I am getting the following error when I am trying to use the > predict > function: > > I'm guessing that the package is really "kernlab". > > > predictSvm = predict(modelforSVM, testSeq); > Error in `contrasts<-`(`*tmp*`, value = "contr.treatment") : > contrasts can > be applied only to factors with 2 or more levels > > Sounds like R does not like the structure of your testSeq argument. > Perhaps it was expecting a factor argument with levels that matched > those used in the training set? > > > The training file is a data frame with 501 columns: Col 1 is "Class" > which > is "+" or "-" and Cols V1 to V500 are "A/C/G/T" . There are 200 > seq's for > training (100 + and - each). this is very similar to the > "promotergene" data > set included as example with the package. > > > The model that I have generated is as follows: > > modelforSVM <- ksvm(Class ~ ., data = train500, kernel = "rbfdot", > kpar = > "automatic", C = 60, cross = 3, prob.model = TRUE) > > The testSeq is a vector of 500 characters casted as a data.frame. I > tried > adding the Class column as well later to the testSeq data frame but > got the > same error. > > Why not offer the results of dput() on that object. Or you could > offer the output of str(testSeq) , even if you aren't going to > create a smaller test object that could be used for testing. > > > I am using R with windows, 32 bit, version 2.9.0 > > Any help that I can get is really appreciated. > > Thanks, > > Vishal > > > David Winsemius, MD David Winsemius, MD Heritage Laboratories West Hartford, CT [[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] how can sample from f(x)∝x^(a-1)
Hello all how can sample from f(x)∝x^(a-1)*ind(0,min(b,-log(u)) in R? where a and b is positive constand and 0https://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 can sample from f(x)~x^(a-1)
Hello all how can sample from f(x)~x^(a-1)*ind(0,min(b,-log(u)) in R? where a and b is positive constand and 0https://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] Multiple CHOLMOD errors when attempting poisson glmm
On Thu, Dec 24, 2009 at 1:03 PM, postava-davig.m wrote: > > Hello, > I have been attempting to run a poisson glmm using lme4 for some time now > and have had a lot of trouble. I would say 9 times out of 10 I receive the > following warning: > CHOLMOD warning: %h > Error in mer_finalize(ans) : > Cholmod error `not positive definite' at > file:../Cholesky/t_cholmod_rowfac.c, line 432 That is an (admittedly obscure) indication that the Cholesky factorization of a matrix derived from the random-effects model matrix cannot be performed. > My data are counts of microbe colony forming units (CFUs) collected from > termite cuticles and the surrounding environment over a 3 year period. I am > attempting to analyze the effect of several factors on these counts (termite > nest volume, temperature, humidity, light, incubation temperature, habitat, > year, sample location, etc.) to determine which account for the variance in > microbial communities. These data are observations, so there are many > missing valueswhich may be part of the problem. I've tried many > different combinations of variables, and also have tried reducing my data > set to remove as many NA's and confounding variables as possible, but I > still can't get any models to work consistently. One most recent attempt > had the following output: model1=lmer(totalcfus~habitat*temp*moisture*light+location+(1|habitat/colony/location),family=poisson,control=list(msVerbose=1)) > 0: 553377.59: 1.00573 0.620530 0.169516 26.3904 -13.1266 -33.2286 > -21.1955 -21.1064 -0.590761 -0.217403 -0.0342272 -0.960593 -0.0962517 > 0.441626 1.20575 0.718621 0.680580 0.171006 0.403729 0.278822 0.275395 > 0.00707767 0.0225599 0.0854869 0.0533373 0.0243451 0.00114120 0.000403226 > -0.00566960 -0.0143715 -0.00931896 -0.00879323 -0.000753236 -0.00335745 > -0.00178054 -0.000788027 -0.000288944 -0.000909455 -0.000839295 -0.000309293 > -1.35885e-05 9.76120e-06 3.57035e-05 2.78985e-05 1.01880e-05 > CHOLMOD warning: %h > Error in mer_finalize(ans) : > Cholmod error `not positive definite' at > file:../Cholesky/t_cholmod_rowfac.c, line 432 Thank you for including the output from verbose = TRUE. It would also help if you included the output from sessionInfo() so we can see which version of R you are using and which version of the lme4 package you are using. How many observations are used in this fit? As you can see, the number of parameters being fit is very large and encountering singularities is not unexpected. May I suggest that we move this discussion to the r-sig-mixed-mod...@r-project.org mailing list, which I have cc:d on this reply? That list is specifically intended for discussions of this type. > I have to admit that I'm at a loss, and have been unable to determine any > pattern to when this error message comes up. I'm hoping that someone can > help me eek out what the issue is with my data so that I can eventually work > out a usable model. > > Thanks so much, and happy holidays. > -- > View this message in context: > http://n4.nabble.com/Multiple-CHOLMOD-errors-when-attempting-poisson-glmm-tp978573p978573.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] How to separate a data set by its factors
On Dec 25, 2009, at 9:38 AM, James Rome wrote: Thanks for the help. I tried making the pdf file as suggested. Acrobat said it was damaged and could not be opened. Is this an R bug? Hard to say. Graphics devices vary from OS to OS and I am on a Mac using a 64 bit bit version of R 2.10.1. I get no error with opening the pdf file so created using either the native Mac graphic viewer, Preview, or the Adobe Acrobat Reader. To decide whether you have identified a bug you would need to provide full sessionInfo and code, and then someone using your OS could try to reproduce the problem. It did make a PostScript file that I was able to distill into PDF, but it was gray scales. How do I get the color back? And yes, I did do the layout I wanted so I could see how the days compared for each hour. On 12/24/09 4:56 PM, David Winsemius wrote: pdf(test.pdf") xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width | Species, data = iris, scales = "free", layout = c(2, 1, 2), auto.key = list(x = .6, y = .7, corner = c(0, 0))) dev.off() You may not be getting what you expect, but it may be that your plots are all being created, but too quickly to be seen. Try printing to a more durable "canvas". And I would like to add a Poisson Distribution fit to each of these plots (see below), but am clueless as to how to go about it. I would like to fit a distribution to the count data for each combination of day and hour, and I am unable to see how to do this in a vector manner. For example, I tried density((Arrival.Val | DAY*Hour), na.rm=TRUE) which does not work. I should think the this would be informative: glm(Arrival.Val ~ DAY*Hour, family="poisson") Since DAY and Hour are factors you will get a large number of estimates. You can use the typical regression functions, such as predict() and summary() to get the fitted values. I tried glm: - glm(Arrival.Val ~ DAY*as.factor(Hour), family="poisson") Call: glm(formula = Arrival.Val ~ DAY * as.factor(Hour), family = "poisson") This output came across rather mangled. Coefficients: (Intercept) DAY[T.Monday] 3.15396 -0.61348 DAY[T.Saturday] DAY[T.Sunday] -0.43853 -0.93475 snipped 0.39860 DAY[T.Tuesday]:as.factor(Hour)[T.23] DAY[T.Wednesday]:as.factor(Hour)[T.23] 0.43209 0.49274 Degrees of Freedom: 8124 Total (i.e. Null); 7963 Residual (18 observations deleted due to missingness) Null Deviance:40120 Residual Deviance: 17030 AIC: 59170 I am not sure what to make of this. Those are estimated Poisson means (on a log-scale) for each of your factors, DAY and Hour. So how do I get the fit plotted on top of my histograms? See if this helps understand how a model relates to a data situation: > testsim <- data.frame(Arrivals = rpois(24*3, lambda=c(rep(10,5),rep(40,4),rep(20,6), rep(40,4), rep(10, 24-5-4-6-4))), Hour= factor(rep(1:24, 3)), DAY=Sys.Date()+1:3 ) >testsim > testsim Arrivals HourDAY 1 91 2009-12-26 2 62 2009-12-27 3103 2009-12-28 4104 2009-12-26 5135 2009-12-27 6346 2009-12-28 7347 2009-12-26 8358 2009-12-27 # output elided (72 lines) > glm(Arrivals ~ Hour, data=testsim) Call: glm(formula = Arrivals ~ Hour, data = testsim) Coefficients: (Intercept)Hour2Hour3Hour4Hour5 Hour6Hour7 8. -1. 0. 0.6667 4. 29.6667 28. Hour8Hour9 Hour10 Hour11 Hour12 Hour13 Hour14 30. 32. 11. 11. 10.6667 11. 12.6667 Hour15 Hour16 Hour17 Hour18 Hour19 Hour20 Hour21 8.6667 31. 26.6667 33. 28.6667 4. -1. Hour22 Hour23 Hour24 0. 4.6667 0. Degrees of Freedom: 71 Total (i.e. Null); 48 Residual Null Deviance: 12400 Residual Deviance: 1004 AIC: 444.1 The estimates are Intercept + factor_coefficient. Is there a way to save the bin data from the histogram command? I don't know if the lattice function supports that, but the base graphics function hist lets you get the breaks and counts. ?hist You might need to wrap it in a call to tapply, since the help page does not say that a formula method is available, and I do not see a formula method with methods(hist). (There might be easier ways to get counts, such as xtabs() which supports a formula method. ?xtabs David Winsemius, MD Heritage Laboratories West Hartford, CT Again Thanks for the prompt holiday response. Jim Rome David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-
[R] [R-pkgs] sqldf 0.2-0
A new version of sqldf, version 0.2-0, has been uploaded to CRAN and should be available on most mirrors by now. NEW - works with the new version of DBI package, DBI 0.2-5. The default action of this version of DBI quotes those column names in select statements that are SQL reserved words (rather than appending __1 to them which was the previous default action). As a result it should no longer be necessary to refer to Time as Time__1, etc. Thus this now works where BOD is a 6 row data frame that comes with R and has the indicated column names: sqldf("select Time, demand from BOD") - if the libspatialite-1.dll sqlite loadable extension is found on PATH then it will automatically be loaded into SQLite the first time sqldf is called in a session. This gives access to several dozen new SQL functions. For a complete list see: http://www.gaia-gis.it/spatialite/spatialite-sql-2.3.1.html For example, stddev_pop and var_pop are functions provided in the dll used in this example: sqldf("select avg(demand) mean, stddev_pop(demand) sd, var_pop(demand) var from BOD") (If the loadable extension is not found then sqldf still works with all the functionality it previously had but the new functions in the loadable extension will, of course, not be available. Note that this loadable extension does not come with sqldf ; however, it is free software distributed under the Mozilla public license and the user may download it from http://www.gaia-gis.it/spatialite/binaries.html and place the dll on their PATH to get automatic access from sqldf). - new filter argument on read.csv.sql - read.csv2.sql added. This is like read.csv.sql but uses a default filter which translates all commas to dots. On Windows it pipes the input file through a custom vbscript that comes with sqldf and on other systems it uses tr , . (In both cases the result is the same.) read.csv2.sql is used to read data files originating in certain European countries. OVERVIEW sqldf is an R package that allows one to manipulate R data frames and input files using SQL from within R. It is layered on top of RSQLite, DBI and the sqlite database. Typical usage involves a single line of R code calling sqldf and containing a string argument which is the select statement. sqldf automatically sets up a database and table definitions, runs the select statement, retrieves the result and destroys the database. For more information including many examples of use see the home page at: http://sqldf.googlecode.com and the help files in the package. ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ 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 separate a data set by its factors
On Dec 25, 2009, at 2:00 PM, David Winsemius wrote: On Dec 25, 2009, at 9:38 AM, James Rome wrote: Thanks for the help. I tried making the pdf file as suggested. Acrobat said it was damaged and could not be opened. Is this an R bug? Hard to say. Graphics devices vary from OS to OS and I am on a Mac using a 64 bit bit version of R 2.10.1. I get no error with opening the pdf file so created using either the native Mac graphic viewer, Preview, or the Adobe Acrobat Reader. To decide whether you have identified a bug you would need to provide full sessionInfo and code, and then someone using your OS could try to reproduce the problem. It did make a PostScript file that I was able to distill into PDF, but it was gray scales. How do I get the color back? And yes, I did do the layout I wanted so I could see how the days compared for each hour. On 12/24/09 4:56 PM, David Winsemius wrote: pdf(test.pdf") Although I do notice a missing ' " '. David Winsemius, MD Heritage Laboratories West Hartford, CT __ 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] Composing a sequence of functions dynammically
Hello, I would like to compose a series of functions each taking one argument. Let us assume the values returned by the functions are contained within the domains. So b<-function(r) r[-1] compose("b","b") b(b(x)) This is my solution, is there something succinct ? Regards Saptarshi compose <- function(...){ fns0 <- list(...) g <- function(x) {} compose2 <- function(fns){ if(length(fns)==1){ as.call(list(as.name(fns[[1]]),quote(x))) }else{ as.call( list( as.name(fns[[ length(fns) ]]), compose2( fns[1:(length(fns)-1)]))) } } body <- compose2(fns0) body(g,envir=parent.frame()) <- body } b <- function(r) r[-1] j=compose("b","b") __ 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] Running 32 bit R in terminal on Mac OS
saleem1000 wrote: > > Hello, > > I am using Mac OS on R. When I start R thru the application menu I have > the option of running both the 32 bit version as well as the 64 bit > version. > > When I type in R in terminal I believe it starts up the 64 bit version. > How can I start the 32 bit version instead?? > > Saleem > > Set the value of the R_ARCH environment variable to either: /i386 or /x86_64 to specify which version gets run when you start R in the terminal. A good place to set this is by adding the following line export R_ARCH=/i386 to ~/.profile Hope this helps! -Charlie -- View this message in context: http://n4.nabble.com/Running-32-bit-R-in-terminal-on-Mac-OS-tp978562p978928.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] input a list into a function
I want to input a list into a function. But i get the error "Error in +{ : invalid argument to unary operator". How do I avoid this error? Here is an example of this problem: > g = c(2, 4, 8, 16, 32, 64, 128, 122, 110, 86, 38, 76, 18, 36, 72, 10, 20, 40, > 80, 26) > for (i in 1:20) + {for (x in 0:20) + print(g[i]+x)} [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 Error in +{ : invalid argument to unary operator [[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] input a list into a function
On Fri, 25-Dec-2009 at 05:27PM -0800, Cat Morning wrote: |> ? |> I want to input a list into a function. But i get the error "Error in +{ : invalid argument to unary operator". How do I avoid this error? |> ? |> Here is an example of this problem: |> ? |> > g = c(2, 4, 8, 16, 32, 64, 128, 122, 110, 86, 38, 76, 18, 36, 72, 10, 20, 40, 80, 26) |> |> > for (i in 1:20) |> ?+ {for (x in 0:20) |> ?+ print(g[i]+x)} |> [1] 2 |> [1] 3 |> [1] 4 |> [1] 5 |> [1] 6 |> [1] 7 |> [1] 8 |> [1] 9 |> [1] 10 |> [1] 11 |> [1] 12 |> [1] 13 |> [1] 14 |> [1] 15 |> [1] 16 |> [1] 17 |> [1] 18 |> [1] 19 |> [1] 20 |> [1] 21 |> [1] 22 |> Error in +{ : invalid argument to unary operator > g = c(2, 4, 8, 16, 32, 64, 128, 122, 110, 86, 38, 76, 18, 36, 72, 10, 20, 40, > 80, 26) > g [1] 2 4 8 16 32 64 128 122 110 86 38 76 18 36 72 10 20 40 80 [20] 26 > for (i in 1:20) { + for (x in 0:20) + print(g[i]+x) + } [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 8 [1] 9 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 31 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 37 [1] 38 [1] 39 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 [1] 47 [1] 48 [1] 49 [1] 50 [1] 51 [1] 52 [1] 64 [1] 65 [1] 66 [1] 67 [1] 68 [1] 69 [1] 70 [1] 71 [1] 72 [1] 73 [1] 74 [1] 75 [1] 76 [1] 77 [1] 78 [1] 79 [1] 80 [1] 81 [1] 82 [1] 83 [1] 84 [1] 128 [1] 129 [1] 130 [1] 131 [1] 132 [1] 133 [1] 134 [1] 135 [1] 136 [1] 137 [1] 138 [1] 139 [1] 140 [1] 141 [1] 142 [1] 143 [1] 144 [1] 145 [1] 146 [1] 147 [1] 148 [1] 122 [1] 123 [1] 124 [1] 125 [1] 126 [1] 127 [1] 128 [1] 129 [1] 130 [1] 131 [1] 132 [1] 133 [1] 134 [1] 135 [1] 136 [1] 137 [1] 138 [1] 139 [1] 140 [1] 141 [1] 142 [1] 110 [1] 111 [1] 112 [1] 113 [1] 114 [1] 115 [1] 116 [1] 117 [1] 118 [1] 119 [1] 120 [1] 121 [1] 122 [1] 123 [1] 124 [1] 125 [1] 126 [1] 127 [1] 128 [1] 129 [1] 130 [1] 86 [1] 87 [1] 88 [1] 89 [1] 90 [1] 91 [1] 92 [1] 93 [1] 94 [1] 95 [1] 96 [1] 97 [1] 98 [1] 99 [1] 100 [1] 101 [1] 102 [1] 103 [1] 104 [1] 105 [1] 106 [1] 38 [1] 39 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 [1] 47 [1] 48 [1] 49 [1] 50 [1] 51 [1] 52 [1] 53 [1] 54 [1] 55 [1] 56 [1] 57 [1] 58 [1] 76 [1] 77 [1] 78 [1] 79 [1] 80 [1] 81 [1] 82 [1] 83 [1] 84 [1] 85 [1] 86 [1] 87 [1] 88 [1] 89 [1] 90 [1] 91 [1] 92 [1] 93 [1] 94 [1] 95 [1] 96 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 31 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 37 [1] 38 [1] 36 [1] 37 [1] 38 [1] 39 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 [1] 47 [1] 48 [1] 49 [1] 50 [1] 51 [1] 52 [1] 53 [1] 54 [1] 55 [1] 56 [1] 72 [1] 73 [1] 74 [1] 75 [1] 76 [1] 77 [1] 78 [1] 79 [1] 80 [1] 81 [1] 82 [1] 83 [1] 84 [1] 85 [1] 86 [1] 87 [1] 88 [1] 89 [1] 90 [1] 91 [1] 92 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 31 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 37 [1] 38 [1] 39 [1] 40 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 [1] 47 [1] 48 [1] 49 [1] 50 [1] 51 [1] 52 [1] 53 [1] 54 [1] 55 [1] 56 [1] 57 [1] 58 [1] 59 [1] 60 [1] 80 [1] 81 [1] 82 [1] 83 [1] 84 [1] 85 [1] 86 [1] 87 [1] 88 [1] 89 [1] 90 [1] 91 [1] 92 [1] 93 [1] 94 [1] 95 [1] 96 [1] 97 [1] 98 [1] 99 [1] 100 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 31 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 37 [1] 38 [1] 39 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 > How different is that from what you're trying to do? -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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] input a list into a function
It works for me, without changes. See below. But I can recreate your error if I type the plus signs at the beginning of second and third lines. For your example, don't type any plus signs, except for the one in print(g[i]+x)} By the way, nothing that you did fits the description "input a list into a function", because you haven't created any lists (your "g" is not a list). -Don At 5:27 PM -0800 12/25/09, Cat Morning wrote: Content-Type: text/plain Content-Disposition: inline Content-length: 595 I want to input a list into a function. But i get the error "Error in +{ : invalid argument to unary operator". How do I avoid this error? Here is an example of this problem: > g = c(2, 4, 8, 16, 32, 64, 128, 122, 110, 86, 38, 76, 18, 36, 72, 10, 20, 40, 80, 26) > for (i in 1:20) + {for (x in 0:20) + print(g[i]+x)} [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 Error in +{ : invalid argument to unary operator [[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. for (i in 1:20) + {for (x in 0:20) + print(g[i]+x)} [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 [1] 9 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 8 [1] 9 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 31 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 37 [1] 38 [1] 39 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 [1] 47 [1] 48 [1] 49 [1] 50 [1] 51 [1] 52 [1] 64 [1] 65 [1] 66 [1] 67 [1] 68 [1] 69 [1] 70 [1] 71 [1] 72 [1] 73 [1] 74 [1] 75 [1] 76 [1] 77 [1] 78 [1] 79 [1] 80 [1] 81 [1] 82 [1] 83 [1] 84 [1] 128 [1] 129 [1] 130 [1] 131 [1] 132 [1] 133 [1] 134 [1] 135 [1] 136 [1] 137 [1] 138 [1] 139 [1] 140 [1] 141 [1] 142 [1] 143 [1] 144 [1] 145 [1] 146 [1] 147 [1] 148 [1] 122 [1] 123 [1] 124 [1] 125 [1] 126 [1] 127 [1] 128 [1] 129 [1] 130 [1] 131 [1] 132 [1] 133 [1] 134 [1] 135 [1] 136 [1] 137 [1] 138 [1] 139 [1] 140 [1] 141 [1] 142 [1] 110 [1] 111 [1] 112 [1] 113 [1] 114 [1] 115 [1] 116 [1] 117 [1] 118 [1] 119 [1] 120 [1] 121 [1] 122 [1] 123 [1] 124 [1] 125 [1] 126 [1] 127 [1] 128 [1] 129 [1] 130 [1] 86 [1] 87 [1] 88 [1] 89 [1] 90 [1] 91 [1] 92 [1] 93 [1] 94 [1] 95 [1] 96 [1] 97 [1] 98 [1] 99 [1] 100 [1] 101 [1] 102 [1] 103 [1] 104 [1] 105 [1] 106 [1] 38 [1] 39 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 [1] 47 [1] 48 [1] 49 [1] 50 [1] 51 [1] 52 [1] 53 [1] 54 [1] 55 [1] 56 [1] 57 [1] 58 [1] 76 [1] 77 [1] 78 [1] 79 [1] 80 [1] 81 [1] 82 [1] 83 [1] 84 [1] 85 [1] 86 [1] 87 [1] 88 [1] 89 [1] 90 [1] 91 [1] 92 [1] 93 [1] 94 [1] 95 [1] 96 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 31 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 37 [1] 38 [1] 36 [1] 37 [1] 38 [1] 39 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 [1] 47 [1] 48 [1] 49 [1] 50 [1] 51 [1] 52 [1] 53 [1] 54 [1] 55 [1] 56 [1] 72 [1] 73 [1] 74 [1] 75 [1] 76 [1] 77 [1] 78 [1] 79 [1] 80 [1] 81 [1] 82 [1] 83 [1] 84 [1] 85 [1] 86 [1] 87 [1] 88 [1] 89 [1] 90 [1] 91 [1] 92 [1] 10 [1] 11 [1] 12 [1] 13 [1] 14 [1] 15 [1] 16 [1] 17 [1] 18 [1] 19 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 20 [1] 21 [1] 22 [1] 23 [1] 24 [1] 25 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 31 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 37 [1] 38 [1] 39 [1] 40 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 [1] 47 [1] 48 [1] 49 [1] 50 [1] 51 [1] 52 [1] 53 [1] 54 [1] 55 [1] 56 [1] 57 [1] 58 [1] 59 [1] 60 [1] 80 [1] 81 [1] 82 [1] 83 [1] 84 [1] 85 [1] 86 [1] 87 [1] 88 [1] 89 [1] 90 [1] 91 [1] 92 [1] 93 [1] 94 [1] 95 [1] 96 [1] 97 [1] 98 [1] 99 [1] 100 [1] 26 [1] 27 [1] 28 [1] 29 [1] 30 [1] 31 [1] 32 [1] 33 [1] 34 [1] 35 [1] 36 [1] 37 [1] 38 [1] 39 [1] 40 [1] 41 [1] 42 [1] 43 [1] 44 [1] 45 [1] 46 -- - Don MacQueen Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 m...@llnl.gov __ 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.