[R] convert matrix to dataframe with repeating row names
Hi R, I have a matrix x with repeating row names. > dim(x) [1] 862 19 zz<-matrix(0,4,4) rownames(zz)=c("a","a","b","b") data.frame(zz) (?) I need to use x in a linear regression lm(as.formula(paste("final_dat[,5]~",paste(colnames(x),collapse="+"))),x ) this gives me a error Error in model.frame.default(formula = as.formula(paste("final_dat[,5]~", : 'data' must be a data.frame, not a matrix or an array > sessionInfo() R version 2.7.1 (2008-06-23) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] xlsReadWrite_1.3.2 Thanks in advance Ravi This e-mail may contain confidential and/or privileged i...{{dropped:13}} __ 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] Select only cases with negative values
> "MJ" == Michael Just <[EMAIL PROTECTED]> > on Sat, 18 Oct 2008 17:26:02 -0400 writes: MJ> Henrique, MJ> This code below from a R-help helper worked. >> dat <-data.frame(f) >> dat2<-dat[dat$d<0,] >> dat.lm <-lm(c~d, data=dat2) But Henrique's advice, of using 'subset= d < 0' was really better (in most respects I'd say). If it really did not work for you, you have a strange (or broken?) R environment. Again back to your example c <- 1:10 d <- c(-1,2,-3,-4,5,6,-7,8,-9,10) f <- cbind(c,d) dat <- data.frame(f) rm(c,d,f) ## << check to make sure 'c' or 'd' are not picked up from GlobalEnv [MM] ## daN.lm <-lm(c ~ d, data = dat, subset = d < 0) summary(daN.lm) Does this really not work for you? Martin Maechler, ETH Zurich MJ> Thanks again, MJ> Michael Just MJ> On Sat, Oct 18, 2008 at 5:22 PM, Henrique Dallazuanna <[EMAIL PROTECTED]> wrote: >> Works for me. >> >> dat.lm <-lm(c~d, data = dat, subset=d < 0) >> >> Please see if you have dat with d and c columns names. >> __ 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] About Torus Rndamiztion
Hallo I am going through the paper on Torus randomization by Kyle E. Harms torus randomization is an alternative to Chi-sq test of Independence When the assumption of independence within the groups is violated i want to know that Is there any library regarding torus randomization Someone said me that its in Utility.r but i could not find out this please help me in this regard Shubham Surendra D. Champanerkar Project Assistant Prof. R. Sukumar lab Center for Ecological Science (CES) Indian Institute Science (IISc) Bangalore 560012 Mobile No: 09739806995 [[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] about "granova" library
Em Qui, 2008-10-16 às 21:11 +1030, Fernando Marmolejo Ramos escreveu: > Dear all > > Recently the "granova" package was launched. I installed but after when I > invoked it in R it requested for other libraries. They were downloaded and > install automatically. > > I tried to run the example syntax of “granova.1w” and “granova.2w” but two > things happened: i) either a file called “granova.rdb” wasn’t existent or ii) > the GUI clashed and R shut down. > > Has anyone else experience this? Do the developers have an answer for this > troubleshot? > > I’m using a Windows Vista system and I have the R version 2.7.2. > > Cheers, > > Fer Fernando I using R version 2.7.2 and Ubuntu 8.04 in my computer: granova.1w - runs fine granova.2w - don't run fine, actual only 1 of 2 graphical windows apear a plot (rgl surface) -- Bernardo Rangel Tura, M.D,MPH,Ph.D National Institute of Cardiology Brazil __ 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] A question about positive definite matrix
I know, this is a forum about R. But I am so desperate of this problem (BTW, anyone knows any good Statistics/Math forum to post question like this?): A and B are both n x n positive definite matrix. Denote A > B, if A - B is positive definite. I know this is true: if A > B, then A^{-1} < B^{-1}. But how to prove this? I tried to diagonalize A and B, but since they can have different eigen structure,... I am stuck here. Thanks a lot for any help here. -- View this message in context: http://www.nabble.com/A-question-about-positive-definite-matrix-tp20063054p20063054.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 2.8.0 is released
I've rolled up R-2.8.0.tar.gz a short while ago. This is a development release which contains a number of new features. Also, a number of mostly minor bugs have been fixed. See the full list of changes below. You can get it (later today) from http://cran.r-project.org/src/base/R-2/R-2.8.0.tar.gz or wait for it to be mirrored at a CRAN site nearer to you. In case of impatience, try http://www.biostat.ku.dk/~pd/R-release Binaries for various platforms will appear in due course. For the R Core Team Peter Dalgaard These are the md5sums for the freshly created files, in case you wish to check that they are uncorrupted: 70447ae7f2c35233d3065b004aa4f331 INSTALL 433182754c05c2cf7a04ad0da474a1d0 README 4f004de59e24a52d0f500063b4603bcb OONEWS ff4bd9073ef440b1eb43b1428ce96872 ONEWS 2e66a7217f24f1d7961275438243adc7 NEWS 1ad28cbc84485ccdf4ce5721b34ed645 THANKS 070cca21d9f8a6af15f992edb47a24d5 AUTHORS a6f89e2100d9b6cdffcea4f398e37343 COPYING.LIB eb723b61539feef013de476e68b5c50a COPYING 020479f381d5f9038dcb18708997f5da RESOURCES 5717a4e29823dd379e4a6cf82e820eb2 FAQ 5213c9644aec984278b669df1a63a2ce R-2.8.0.tar.gz 5213c9644aec984278b669df1a63a2ce R-latest.tar.gz This is the relevant part of the NEWS file: CHANGES IN R VERSION 2.8.0 SIGNIFICANT USER-VISIBLE CHANGES o var(), cov(), cor(), sd() etc now by default (when 'use' is not specified) return NA in many cases where they signalled an error before. NEW FEATURES o abbreviate() gains an optional argument 'strict' allowing cheap and fast strict abbrevation. o The "lm" methods of add1(), anova() and drop1() warn if they are mis-used on an essentially exact fit. o as.array() is now generic, gains a '...' argument. o New function as.hexmode() for converting integers in hex format. format.hexmode() and as.character.hexmode() gain an 'upper.case' argument. o bitmap() and dev2bitmap() gain support for anti-aliasing. The default type has been changed to 'png16m', which supports anti-aliasing. o Box.test() gains a 'fitdf' argument to adjust the degrees of freedom if applied to residuals. o browseURL() has a new argument 'encodeIfNeeded' to use URLencode() in cases where it seems likely that would be helpful. (Unfortunately, those are hard to guess.) o by() gains a 'simplify' argument, passed to tapply(). o capabilities() gains a new argument "tiff" to report if tiff() is operational. o chol2inv() now treats as a [1 x 1]-matrix. o cov() and cor() have the option 'use = "everything"' as default, and so does var() with its default 'na.rm = FALSE'. This returns NA instead of signalling an error for NA observations. Another new option is 'use = "na.or.complete"' which is the default for var(*, na.rm=FALSE). var(double(0), na.rm= L) now returns NA instead of signalling an error, for both L = TRUE or FALSE, as one consequence of these changes. o data.matrix() now tries harder to convert non-numeric columns, via as.numeric() or as(, "numeric"). o dev.interactive() is able to recognize the standard screen devices if getOption("device") is a function (as well as by name). o dev.new() gains a '...' argument which can be used to pass named arguments which will be used if appropriate to the device selected. o dimnames(x) <- value extends 'value' if it a list and too short, and 'x' is an array. This allows constructions such as dimnames(x)[[1]] <- 1:3 to work whether or not 'x' already has dimnames. o format(), formatC() and prettyNum() gain a new argument 'drop0trailing' which can be used to suppress trailing "0"s. o format() now works for environments; also print(env) and str(env) share the same code for environments. o It is now possible to create and open a text-mode gzfile() connection by explicitly using e.g. open="rt". o New help.request() function for compiling an e-mail to R-help according to "the rules". It is built on the new utility, create.post() on which also bug.report() is based now; both thanks to a contribution by Heather Turner. o help.search() now assumes that non-ASCII items are in latin1 if that makes sense (all known examples on CRAN are). o HoltWinters() and decompose() use a (statistically) more efficient computation for seasonal fits (they used to waste one period). o intToUtf8() and intToBits() now accept numeric vectors, truncating them to integers. o is.unsorted() gains an argument 'strictly'. It now works for classed objects with a >= or > method (as incorrectly documented earlier). o library() no longer warns about the masking object
Re: [R] convert matrix to dataframe with repeating row names
On Mon, 20 Oct 2008, [EMAIL PROTECTED] wrote: I have a matrix x with repeating row names. zz<-matrix(0,4,4) rownames(zz)=c("a","a","b","b") data.frame(zz) (?) The row names on a data frame should be unique. You can try as.data.frame(xx, row.names=FALSE) to convert zz to be a data frame. If you need the row name information, add it as a column in the data frame, e.g. mydataframe$rnames <- rownames(zz). (Note to R-Core: the documentation for as.data.frame doesn't mention the usage of row.names=FALSE to ignore row names, but it seems to work consistently. Does the help page for as.data.frame need updating?) No. row.names=FALSE is not intended to work, and did you check every single as.data.frame() method? It just so happens that for the matrix method invalid input for 'row.names' results in setting default row names. Other methods may differ. lm(as.formula(paste("final_dat[,5]~",paste(colnames(x),collapse="+"))),x ) this gives me a error Error in model.frame.default(formula = as.formula(paste("final_dat[,5]~", : 'data' must be a data.frame, not a matrix or an array I suspect that if you try class(x), it will be a matrix, not the requisite data frame. Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] Bootstrap problem
Dear R-users, I'm having a small problem while bootstraping data. What i would like to do, is resmple the data and calulate a function on this, so i can estimate the measure of reproducability for this data. The function i wrote works fine, even while bootstraping. The only problem is that bootstraping. The dataset existes of 10 trials, each divided in to 3 groups of high(3) medium(2) and low(1). A bootstrap samlpe (trial) should always exist of 5 obs. taken from each group population, so to be representative. example: original data: trial 1 : group(1) = (0,0,1,0,0);group(2) = (0,1,1,0,1);group(3) = (1,1,1,1,1) ... bootstraped data: trial 1 : group(1) = (0,0,0,0,1);group(2) = (1,1,0,0,1);group(3) = (1,0,1,1,1) NOT bootstraped data: trial 1 : group(1) = (0,0,0,0,1,1,0);group(2) = (1,0,1);group(3) = (1,0,1,1,1,1,1,0,1,1) Now I am familiar how to use function "bootstrap" (pkg "bootstrap"), but i read about a function called "boot" (pkg "boot"), however i can't seem to master this. The explanation (help('boot') ) isn't making me any smarter. I know I can always split the data up (wich is what i am doing) but i was wondering whether this would have an effect on the bootstrap, maby it is beter to keep all the groups together? here is a (this time WORKING) code example of what i did. ## proc ## generate data datas <- data.frame("protection"=c(rep(c(0,1,0,1,0,0,1,0,1,1,1,0,1,1,1),2),c(0,0,0,0,1,0,1,0,1,1,1,0,1,0,1),rep(c(0,1,1,1,0,0,1,1,0,1,1,1,1,0,1),2),c(0,1,0,0,1,0,1,1,1,1,1,1,1,1,1),rep(c(0,1,0,1,0,0,1,1,1,1,1,0,1,1,1),2),c(0,1,0,0,0,0,1,1,0,1,1,1,1,1,1),c(0,0,1,1,0,0,1,1,1,0,0,1,1,0,1)) ,"group"=rep(1:3,50),"trial"=c(rep(1,15),rep(2,15),rep(3,15),rep(4,15),rep(5,15),rep(6,15),rep(7,15),rep(8,15),rep(9,15),rep(10,15))) ## describe Function Vacc.Vcon <-function (dataset1 , trialdata , groupdata ) { groups <- unique (groupdata) trials <- unique (trialdata) Tr <- length(trials) G <- length(groups) Gl <- length(dataset1)/(G*Tr) Tl <- length(dataset1)/(Tr) iterg <-data.frame(1:G,as.vector(groups)) trials <- unique (trialdata) Tr <- length(trials) itert <-data.frame(1:Tr,as.vector(trials)) triallist <- c() grouplist <- c() for (x in 1:G){ ifelse(x==1,y<-x,y<- y+Tr) grouplist[c(y:(y+Tr-1))] <-rep(iterg[x,2],Tr)} iter <-data.frame(1:(Tr),rep(trials,G),grouplist) VACC <- data.frame() VACC.sub <- function (dataset1,trialn,groupn){ p0 <-sum( ifelse(dataset1==1 & trialdata==trialn & groupdata==groupn, 1,0) ) p1 <-sum( ifelse(dataset1==0 & trialdata==trialn & groupdata==groupn, 1,0) ) p <- p0+p1 VACC.group <- list('Trial'=trialn,'Group'=groupn,'Vacc'=sum((p0/p)^2 ,(p1/p)^2),"p0"=(p0/p) , "p1"=(p1/p) ,"n0"=as.numeric(p0),"n1"=as.numeric(p1),'n'=as.numeric(p)) VACC.group} for (i in 1:(G*Tr) ) { VACC[i,1] <- VACC.sub (dataset1,iter[i,2],iter[i,3])[1] VACC[i,2] <- VACC.sub (dataset1,iter[i,2],iter[i,3])[2] VACC[i,3] <- VACC.sub (dataset1,iter[i,2],iter[i,3])[3] VACC[i,4] <- VACC.sub (dataset1,iter[i,2],iter[i,3])[4] VACC[i,5] <- VACC.sub (dataset1,iter[i,2],iter[i,3])[5] VACC[i,6] <- VACC.sub (dataset1,iter[i,2],iter[i,3])[6] VACC[i,7] <- VACC.sub (dataset1,iter[i,2],iter[i,3])[7] VACC[i,8] <- VACC.sub (dataset1,iter[i,2],iter[i,3])[8] VACC} rownames(VACC) <- NULL rownames(VACC) <- paste(iter[,2],iter[,3],sep='_') Pcalc <- function(x) { out<-(1/(Tr)) * sum(x) out} P0 <- tapply( VACC$p0,VACC$Group,Pcalc) P1 <- tapply( VACC$p1,VACC$Group,Pcalc) Vcon <- mean(cbind(P0^2 + P1^2)) Vacc.total <- mean (tapply( VACC$Vacc,VACC$Group,mean)) out <- list("all"=VACC,"N"=G,"P0"=P0,"P1"=P1,"Vcon"=Vcon*100,"Vacc.total"=Vacc.total*100) out } ## end describe Function Vacc.Vcon (datas[,1] , datas[,3], datas[,2]) # example of how fun works ## data needs to be in matrix form for bootstrap function xdata <-matrix( cbind(datas$protection,datas$group,datas$trial),ncol=3,byrow=F) ## function for bootstrap vacc.boot <- function(x,xdata){ Vacc.Vcon(xdata[x,1],xdata[x,3],xdata[x,2]) } bootk <- 10 results <- bootstrap(1:150,bootk,vacc.boot,xdata) taccs <- list() ;Vaccs <- vector();Vcons <- vector() boot.amp.vac2<- for(i in 1:bootk) { m.i <- results$thetastar[[i]] taccs[i] <- list(m.i ) G.Vacc <- round( tapply(taccs[[i]]$all$Vacc,rownames(taccs[[i]]$all),mean)*100 ,digits=3) Vaccs <- round( mean(taccs[[i]]$Vacc.total),digits=3) Vcons<-round( mean(taccs[[i]]$Vcon ),digits=3) tacc <- list( "data"=taccs,"Booted.means"=list("Vacc.grouped"=G.Vacc ,"Vacc.Total"=Vaccs,"Vcon.Total"=Vcons)) tacc} Rep.table <- tacc$Booted.mean Rep.table ## problem area => n should always be 5 in each group as in the original data #calcues based on original data last colon : n = 5 Vacc.Vcon (datas[,1
Re: [R] Extracting variables with a given prefix in the parent environment
On 20/10/2008 2:06 AM, erwann rogard wrote: hi, get.vars.name.prefix<-function(prefix){ result<-list() len<-nchar(prefix) var.names<-ls(name=1,pattern=prefix) #name=1 probably wrong option print(var.names) for(i in 1:length(var.names)){ name<-var.names[i] field<-substr(name,len+1,nchar(name)) result[[field]]<-get(name) } result } for example x.1<-1 x.2<-2 get.vars.name.prefix("x.") should return 1,2 this does not work if i call if from within another function: g<-function(){ x.1<-1 x.2<-2 get.vars.name.prefix("x.") # should return 1,2, nothing else } i would like the environment specified within ls(...) to be that of the body of the function that calls get.vars.name.prefix. apparently name=1 is probably not the right option. Use ls(name=parent.frame(), pattern=...) And be careful about the pattern: it's a regular expression, so you would need to start with a caret "^" to guarantee that it occurs at the start of the name. Duncan Murdoch __ 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] convert matrix to dataframe with repeating row names
> > The row names on a data frame should be unique. You can try > > as.data.frame(xx, row.names=FALSE) to convert zz to be a data frame. If > > you need the row name information, add it as a column in the data frame, > > e.g. mydataframe$rnames <- rownames(zz). (Note to R-Core: the > > documentation for as.data.frame doesn't mention the usage of > > row.names=FALSE to ignore row names, but it seems to work consistently. > > Does the help page for as.data.frame need updating?) > > No. row.names=FALSE is not intended to work, and did you check every > single as.data.frame() method? > > It just so happens that for the matrix method invalid input for > 'row.names' results in setting default row names. Other methods may > differ. row.names=FALSE seems a natural way of supressing existing row names to me, since it corresponds nicely to using row.names=FALSE in write.csv. Currently it seems that if a matrix has duplicate row names, then converting it to be a data frame requires rnames <- rownames(mymatrix) rownames(mymatrix) <- NULL as.data.frame(mymatrix) rownames(mymatrix) <- rnames Ideally, three of these lines of code shouldn't really need to be there. If you disagree that allowing row.names=FALSE is a good idea, or you don't want to change the function interface, then perhaps having as.data.frame check for duplicates and throwing a warning (rather than an error) would be preferable behaviour. I do realise that there are dozens of as.data.frame methods, and the documentation does state that "Few of the methods check for duplicated row names", but it would be beneficial from a user standpoint. Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error reporting in R
Hello, I am hoping someone can help me with the following: I am applying the function "mle" on a single data set X n times, each time using a different set of initial values v[i] (i=1,...,n). The initial values are all finite. Two cases arise: A- For some sets of initial values mle is giving parameter estimates. B- For some other initial values, mle is reporting the following error: Error in optim(start,f,method=method,hessian=TRUE,...): Initial value in vmin is not finite My aim is to tell R to return the estimates whenever case A, and to return the word "Error" whenever case B (using an "if" statement inside a loop). How to tell R to return the word "Error" whenever mle reports the error given above? Is there a function similar to is.nan which tests the existence of an error? Any assistance would be much appreciated, Regards, Amy - The Open University is incorporated by Royal Charter (RC 000391), an exempt charity in England & Wales and a charity registered in Scotland (SC 038302). [[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] pairs plots in R
If you want to do efficient exploratory data analysis on this kind of dataset, then interactive graphics with parallel coordinate plots (ipcp in iplots) should help. Of course, it depends what you mean by large. It might be worth looking at the book "Graphics of Large Datasets" for some ideas. Antony Unwin Professor of Computer-Oriented Statistics and Data Analysis, Mathematics Institute, University of Augsburg, 86135 Augsburg, Germany Tel: + 49 821 5982218 > > From: "Sharma, Dhruv" <[EMAIL PROTECTED]> > Date: 19 October 2008 10:58:53 pm GMT+02:00 > To: > Subject: [R] pairs plots in R > > > Hi, > is there a way to take a data frame with 100+ columns and large > data set to do efficient exploratory analysis in R with pairs? > > I find using pairs on the whole matrix is slow and the resulting > matrix is tiny. > > Also the variable of interest for me is a binary var Y or N . > > Is there an efficient way to graphically view many variable > relationships that does not look teeny ? > > I could do pairs 10 at a time but this seems too brute force. > > thanks > Dhruv [[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] Extracting variables with a given prefix in the parent environment
Try this: Using 'envir' argument, in ls and get function: get.vars.name.prefix<-function(prefix, envir = parent.frame()){ result<-list() len<-nchar(prefix) var.names<-ls(envir = envir,pattern=prefix) print(var.names) for(i in 1:length(var.names)){ name<-var.names[i] field<-substr(name,len+1,nchar(name)) result[[field]]<-get(name, envir = envir) } result } On Mon, Oct 20, 2008 at 4:06 AM, erwann rogard <[EMAIL PROTECTED]>wrote: > hi, > > get.vars.name.prefix<-function(prefix){ > result<-list() > len<-nchar(prefix) > var.names<-ls(name=1,pattern=prefix) #name=1 probably wrong option > print(var.names) > for(i in 1:length(var.names)){ > name<-var.names[i] > field<-substr(name,len+1,nchar(name)) > result[[field]]<-get(name) > } > result > } > > for example > x.1<-1 > x.2<-2 > get.vars.name.prefix("x.") should return 1,2 > > this does not work if i call if from within another function: > > g<-function(){ > x.1<-1 > x.2<-2 > get.vars.name.prefix("x.") # should return 1,2, nothing else > } > > i would like the environment specified within ls(...) to be that of the > body > of the function that calls get.vars.name.prefix. apparently name=1 is > probably not the right option. > > thanks. > >[[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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[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] problem with multiple comparison
Dear all, I'm a new user of R. How to manage R to have homogeneous means groups with Duncan test? I've tried the Duncan test and the results is the difference between means taken in pairs. Patrice __ ble contre les messages non sollicités [[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] Trying to pass arrays as arguments to a function
I'd like to avoid looping through an array in order to change values in the array as it takes too long. I red from an earlier post it can be done by "do.call" but never got it to work. The Idea is to change the value of "y" according to values in "x". Wherever "x" holds the value 3, the corresponding value in "y" should be set to 1. So I tried the following giving an error message: # x <- c(1,2,3,2,2,3,1,1,3,3) y <- c(0,0,1,1,0,0,1,0,0,1) Change_y <- function() { if (x == 3) {y <- 1} } do.call("Change_y", as.list(x,y)) Error in Change_y(1, 2, 3, 2, 2, 3, 1, 1, 3, 3) : unused argument(s) ( ...) ## How should it be done? Cheers, Kare [[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] Trying to pass arrays as arguments to a function
y <- ifelse(x == 3, 1, y) -Kaom On Oct 20, 2008, at 6:07 AM, Kåre Edvardsen wrote: I'd like to avoid looping through an array in order to change values in the array as it takes too long. I red from an earlier post it can be done by "do.call" but never got it to work. The Idea is to change the value of "y" according to values in "x". Wherever "x" holds the value 3, the corresponding value in "y" should be set to 1. So I tried the following giving an error message: # x <- c(1,2,3,2,2,3,1,1,3,3) y <- c(0,0,1,1,0,0,1,0,0,1) Change_y <- function() { if (x == 3) {y <- 1} } do.call("Change_y", as.list(x,y)) Error in Change_y(1, 2, 3, 2, 2, 3, 1, 1, 3, 3) : unused argument(s) ( ...) ## How should it be done? Cheers, Kare [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Trying to pass arrays as arguments to a function
On Mon, Oct 20, 2008 at 03:07:45PM +0200, Kåre Edvardsen wrote: > I'd like to avoid looping through an array in order to change values in > the array as it takes too long. > I red from an earlier post it can be done by "do.call" but never got it > to work. The Idea is to change the value of "y" according to values in > "x". Wherever "x" holds the value 3, the corresponding value in "y" > should be set to 1. This should do what you want - no looping required: y[x==3] <- 1 cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel __ 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] Trying to pass arrays as arguments to a function
> I'd like to avoid looping through an array in order to change values in > the array as it takes too long. > I red from an earlier post it can be done by "do.call" but never got it > to work. The Idea is to change the value of "y" according to values in > "x". Wherever "x" holds the value 3, the corresponding value in "y" > should be set to 1. y [x == 3] <- 1 -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 (0 40) 5 58-34 47 email: [EMAIL PROTECTED] __ 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] Dep setting for install of packages... EOT (I think) and my thanks
Gabor Grothendieck wrote: leaps is not in Depends or Imports for car. It is in Suggests and those don't get automatically pulled in when dependencies = NA. What you could do is to replace the builtin menuInstallPkgs with your own by running this: assignInNamespace("menuInstallPkgs", function (type = getOption("pkgType")) { install.packages(NULL, .libPaths()[1], dependencies = TRUE, type = type) }, ns = "utils") You will need to do that in every session that you want to use the install menu or you could just add it to your Rprofile.site file which you can find by running this: file.path(R.home(), "etc", "Rprofile.site") So, if I'm understanding this correctly, for a simple, one libpath() situation like mine dep = NA will catch depends and imports, while dep = TRUE will catch those two plus anything under suggests. From prior discussion and suggested reading I take it I would use dep = FALSE to catch the first two if I had multiple locations in libpath() while dep = TRUE behaviour would stay the same. In putting the above code snippet into the Rprofile file, does it need to be all on one line or can it spread over multiple lines as it appears above? My thanks for your time and patient assistance in finding the answers. It is very much appreciated and useful. Regards... -- Brian Lunergan Nepean, Ontario Canada --- __ 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] Date classes in ggplot2
Is not melt part of reshape package, i.e., require(reshape)? DaveT. >-Original Message- >From: stephen sefick [mailto:[EMAIL PROTECTED] >Sent: October 19, 2008 12:12 PM >To: hadley wickham >Cc: R Help >Subject: Re: [R] Date classes in ggplot2 > >well I must have either resolve it without knowing it, ot something >funny is going on... sorry I didn't run it in a clean R session. >Should have. works fine >thanks > >Stephen Sefick > >On Sun, Oct 19, 2008 at 12:01 PM, hadley wickham ><[EMAIL PROTECTED]> wrote: >> On Sun, Oct 19, 2008 at 10:49 AM, stephen sefick ><[EMAIL PROTECTED]> wrote: >>> updn.gg <- (structure(list(date = structure(c(11808, 11869, >11961, 11992, >>> 12084, 12173, 12265, 12418, 12600, 12631, 12753, 12996, 13057, >>> 13149), class = "Date"), unrestored = c(1.13789418691602, >0.704948049842955, >>> 0.276777348238899, 0.417586861554189, 0.504870337754768, >0.673201771716216, >>> 0.560704221510771, 0.835737007551542, 1.10773858390693, >0.197070828834836, >>> 0.942350681588179, 0.950447141061461, 0.246637790002705, >0.324035567509960 >>> ), restored = c(1.39981554315924, 0.89196314359498, >0.407816250252697, >>> 0.823496839063978, 1.14429021220358, 1.23971035967413, >0.960868900583432, >>> 0.927685306209829, 1.22072345292821, 0.249842897450642, >1.00879641624694, >>> 0.925372139878243, 0.317259909172362, 0.382677149697482)), >.Names = c("date", >>> "unrestored", "restored"), row.names = c(NA, -14L), class = >"data.frame")) >>> >>> #I would like to do this in ggplot >>> xyplot(unrestored+restored~date, data=updn.gg, type=c("l"), >auto.key=TRUE) >>> #this is what I have tried and get an error message >>> melt.updn <- melt(updn.gg, id.var="date") >> >> What error message? It works for me. >> >> Hadley >> >> -- >> http://had.co.nz/ >> > > > >-- >Stephen Sefick >Research Scientist >Southeastern Natural Sciences Academy > >Let's not spend our time and resources thinking about things that are >so little or so large that all they really do for us is puff us up and >make us feel like gods. We are mammals, and have not exhausted the >annoying little problems of being mammals. > > >-K. Mullis > > > __ 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] Date classes in ggplot2
yes it is, I meant without the clutter of my previous analyses - reshape is required by ggplot2 so I had that covered... If I am understanding you correctly. thanks for all of the help, Stephen On Mon, Oct 20, 2008 at 9:39 AM, Thompson, David (MNR) <[EMAIL PROTECTED]> wrote: > Is not melt part of reshape package, i.e., require(reshape)? > > DaveT. >>-Original Message- >>From: stephen sefick [mailto:[EMAIL PROTECTED] >>Sent: October 19, 2008 12:12 PM >>To: hadley wickham >>Cc: R Help >>Subject: Re: [R] Date classes in ggplot2 >> >>well I must have either resolve it without knowing it, ot something >>funny is going on... sorry I didn't run it in a clean R session. >>Should have. works fine >>thanks >> >>Stephen Sefick >> >>On Sun, Oct 19, 2008 at 12:01 PM, hadley wickham >><[EMAIL PROTECTED]> wrote: >>> On Sun, Oct 19, 2008 at 10:49 AM, stephen sefick >><[EMAIL PROTECTED]> wrote: updn.gg <- (structure(list(date = structure(c(11808, 11869, >>11961, 11992, 12084, 12173, 12265, 12418, 12600, 12631, 12753, 12996, 13057, 13149), class = "Date"), unrestored = c(1.13789418691602, >>0.704948049842955, 0.276777348238899, 0.417586861554189, 0.504870337754768, >>0.673201771716216, 0.560704221510771, 0.835737007551542, 1.10773858390693, >>0.197070828834836, 0.942350681588179, 0.950447141061461, 0.246637790002705, >>0.324035567509960 ), restored = c(1.39981554315924, 0.89196314359498, >>0.407816250252697, 0.823496839063978, 1.14429021220358, 1.23971035967413, >>0.960868900583432, 0.927685306209829, 1.22072345292821, 0.249842897450642, >>1.00879641624694, 0.925372139878243, 0.317259909172362, 0.382677149697482)), >>.Names = c("date", "unrestored", "restored"), row.names = c(NA, -14L), class = >>"data.frame")) #I would like to do this in ggplot xyplot(unrestored+restored~date, data=updn.gg, type=c("l"), >>auto.key=TRUE) #this is what I have tried and get an error message melt.updn <- melt(updn.gg, id.var="date") >>> >>> What error message? It works for me. >>> >>> Hadley >>> >>> -- >>> http://had.co.nz/ >>> >> >> >> >>-- >>Stephen Sefick >>Research Scientist >>Southeastern Natural Sciences Academy >> >>Let's not spend our time and resources thinking about things that are >>so little or so large that all they really do for us is puff us up and >>make us feel like gods. We are mammals, and have not exhausted the >>annoying little problems of being mammals. >> >> >>-K. Mullis >> >> >> > -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ 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-pkgs] New verion 0.3-7 of gsubfn package
Version 0.3-7 of the gsubfn package is available on CRAN. Changes to the package are: - all known bugs have been fixed. - in gsubfn and strapply the replacement object can be a list (or a function, formula, character string or proto object, as before). In the case of a list, regexp matches are looked up in the list names and the corresponding list component used. # Example 1 - at string end replace M with e6 & G with e9 gsubfn(".$", list(M = "e6", G = "e9"), c("19G", "32.5M")) - the backref= argument in gsubfn now defaults to the negative of its prior default. Thus by default if there are back references only they and not the entire match is passed to the user function. (Although the changed default introduces an incompatibility with prior versions this incompatability is small because it only affects situations where back references are present in the regular expression _and_ backref= was not used. Since the previous default for backref= was not useful in that case there would be very few, if any, such instances.) On the other hand, it does mean that the backref= argument can be omitted most cases now. For more info, see home page and brief description below. http://gsubfn.googlecode.com The gsubfn package - summary A seemingly small enhancement to R's gsub function, allowing the replacement string to be a function, formula, list or proto object gives surprising additional power allowing parsing of strings by content rather than delimiters. e.g. extract numbers: # Example 2. Replace each number with its increment gsubfn("[0-9]+", ~ as.numeric(x) + 1, "90 and 17") # Example 3. extract numbers strapply("Over 90 stones in 17 places", "[0-9]+") The optional function passed to gsubfn and strapply may be specified using usual R function notation or by a formula whose left hand side represents the arguments (defaulting to variables appearing in right hand side) and whose right hand side represents the body. In order to extend this functionality beyond gsubfn and strapply to the rest of R any R function may be prefaced with fn$ like this: # Example 4. Integrate x^2 fn$integrate(~ x^2, 0, 1) It also supports quasi-perl style string interpolation: # Example 5. Quasi-perl style string interpolation fn$cat("pi = $pi and e = `exp(1)`\n") match.funfn is an alternative to match.fun which allows developers to add this functionality to their own functions by simply replacing match.fun with match.funfn -- a one line change. In that case even the fn$ prefix is not needed. ___ R-packages mailing list [EMAIL PROTECTED] 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] pairs plots in R
Thanks Felix. Regards, Dhruv -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Felix Andrews Sent: Sunday, October 19, 2008 11:37 PM To: Sharma, Dhruv Cc: r-help@r-project.org Subject: Re: [R] pairs plots in R One idea: if the primary variable of interest is a categorical (binary), I would rather look at univariate plots for each of your 100 variables, grouped by the primary one. e.g. library(latticeExtra) marginal.plot(~ myBigDat, data = myBigData, groups = myBinaryVar, auto.key = TRUE, layout = c(4, 4)) (This is a convenient interface to lattice::densityplot and lattice::dotplot) If you view 16 such densityplots per page, that still gives you 7 pages. You could use playwith() (from playwith package) to scroll through the pages. -Felix 2008/10/20 Sharma, Dhruv <[EMAIL PROTECTED]>: > Hi, > is there a way to take a data frame with 100+ columns and large data set to > do efficient exploratory analysis in R with pairs? > > I find using pairs on the whole matrix is slow and the resulting matrix is > tiny. > > Also the variable of interest for me is a binary var Y or N . > > Is there an efficient way to graphically view many variable relationships > that does not look teeny ? > > I could do pairs 10 at a time but this seems too brute force. > > thanks > Dhruv > >[[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. > -- Felix Andrews / 安福立 http://www.neurofractal.org/felix/ 3358 543D AAC6 22C2 D336 80D9 360B 72DD 3E4C F5D8 __ 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] Dep setting for install of packages... EOT (I think) and my thanks
You can put the code on several lines as shown or on one line. Does not matter. Read the info on the dependencies= arg in ?install.packages for the definitive explanation of how dependencies= works. On Mon, Oct 20, 2008 at 9:32 AM, Brian Lunergan <[EMAIL PROTECTED]> wrote: > Gabor Grothendieck wrote: >> >> leaps is not in Depends or Imports for car. It is in Suggests >> and those don't get automatically pulled in when dependencies = NA. >> >> What you could do is to replace the builtin menuInstallPkgs with >> your own by running this: >> >> assignInNamespace("menuInstallPkgs", function (type = >> getOption("pkgType")) { >>install.packages(NULL, .libPaths()[1], dependencies = TRUE, type = >> type) >> }, ns = "utils") >> >> You will need to do that in every session that you want to use the install >> menu or you could just add it to your Rprofile.site file which you >> can find by running this: >> >> file.path(R.home(), "etc", "Rprofile.site") > > So, if I'm understanding this correctly, for a simple, one libpath() > situation like mine dep = NA will catch depends and imports, while dep = > TRUE will catch those two plus anything under suggests. From prior > discussion and suggested reading I take it I would use dep = FALSE to catch > the first two if I had multiple locations in libpath() while dep = TRUE > behaviour would stay the same. > > In putting the above code snippet into the Rprofile file, does it need to be > all on one line or can it spread over multiple lines as it appears above? > > My thanks for your time and patient assistance in finding the answers. It is > very much appreciated and useful. > > Regards... > -- > > Brian Lunergan > Nepean, Ontario > Canada > > > --- > avast! Antivirus: Outbound message clean. > Virus Database (VPS): 081018-0, 2008-10-18 > Tested on: 2008-10-20 09:32:23 > avast! - copyright (c) 1988-2008 ALWIL Software. > http://www.avast.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] pairs plots in R
thanks Antony. regards, Dhruv From: Antony Unwin [mailto:[EMAIL PROTECTED] Sent: Monday, October 20, 2008 7:00 AM To: r-help@r-project.org Cc: Sharma, Dhruv Subject: Re: [R] pairs plots in R If you want to do efficient exploratory data analysis on this kind of dataset, then interactive graphics with parallel coordinate plots (ipcp in iplots) should help. Of course, it depends what you mean by large. It might be worth looking at the book "Graphics of Large Datasets" for some ideas. Antony Unwin Professor of Computer-Oriented Statistics and Data Analysis, Mathematics Institute, University of Augsburg, 86135 Augsburg, Germany Tel: + 49 821 5982218 From: "Sharma, Dhruv" <[EMAIL PROTECTED]> Date: 19 October 2008 10:58:53 pm GMT+02:00 To: Subject: [R] pairs plots in R Hi, is there a way to take a data frame with 100+ columns and large data set to do efficient exploratory analysis in R with pairs? I find using pairs on the whole matrix is slow and the resulting matrix is tiny. Also the variable of interest for me is a binary var Y or N . Is there an efficient way to graphically view many variable relationships that does not look teeny ? I could do pairs 10 at a time but this seems too brute force. thanks Dhruv [[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] Package Deal
Hi, I was trying to adjust an bayesian network with Deal package. I know how to adjust when I give the structure and when I don't give the struture. Now, I want to adjust when I know some variables relationships and others I don't know. Anybody knows how can I do that? Regards, Atenciosamente, Leandro Lins Marino Centro de Avaliação Fundação CESGRANRIO Rua Santa Alexandrina, 1011 - 2º andar Rio de Janeiro, RJ - CEP: 20261-903 ( (21) 2103-9600 R.:236 ( (21) 8777-7907 * [EMAIL PROTECTED] "Aquele que suporta o peso da sociedade é precisamente aquele que obtém as menores vantagens". (SMITH, Adam) P Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO AMBIENTE __ 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] Error reporting in R
On 20/10/2008 5:39 AM, A.Noufaily wrote: Hello, I am hoping someone can help me with the following: I am applying the function "mle" on a single data set X n times, each time using a different set of initial values v[i] (i=1,...,n). The initial values are all finite. Two cases arise: A- For some sets of initial values mle is giving parameter estimates. B- For some other initial values, mle is reporting the following error: Error in optim(start,f,method=method,hessian=TRUE,...): Initial value in vmin is not finite My aim is to tell R to return the estimates whenever case A, and to return the word "Error" whenever case B (using an "if" statement inside a loop). How to tell R to return the word "Error" whenever mle reports the error given above? Is there a function similar to is.nan which tests the existence of an error? Normally an error halts evaluation, but see ?try. The basic pattern is result <- try(mle(...)) if (inherits(result, "try-error")) return("Error") else return(result) Duncan Murdoch __ 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] The evaluation of optional function arguments
Hullo all, [***recap of the question: passing bar=harry fails when bar is among the ... args.] callTimes <- function(tom, harry) { timesDefineInside(foo=tom, bar=harry } timesDefineInside <- function(foo, ...) { foo * bar } callTimes(3, 4) # Error: object "bar" not found [***end recap] On 20/10/2008, hadley wickham <[EMAIL PROTECTED]> wrote: > Why don't you want to do this? > > timesDefineInside <- function(foo, bar...) { >foo * bar > } You're right that's it the obvious solution — the thing is, I'm hacking on somebody else's function, and in the interim I want to maintain backward compatibility. Part of that is expecting the same set of formals, so any extra arguments (in this case, 'bar' is actually 'experimentalMode') have to come throught the dots. Kaom Te wrote: > Try this for timesDefineInside: > timesDefineInside <- function(foo, ...) { >extra.args <- list(...) >bar <- extra.args$bar >foo * bar > } Ah, that works! Apparently, there's a difference between list(...) and match.call(expand.dots=FALSE)$... # wrapped in eval() or not. That makes sense, though, as the first will have evaluated bar=harry at the moment of calling, within the calling function, while the second will evaluated bar=harry within the called function. I think. Thank you both very much; and thanks, too, to Martin Morgan, who replied off-list pointing me at bar <- eval.parent(match.call()$bar) . Grateful regards, Sietse Sietse Brouwer -- Sietse Brouwer -- [EMAIL PROTECTED] -- +31 6 13456848 Wildekamp 32 -- 6721 JD Bennekom -- the Netherlands MSN: [EMAIL PROTECTED] -- ICQ: 341232104 __ 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] Combining all possible values of variables into a new...
I'm trying to create a new column in my data.frame where subjects are categorized depending on values on four other columns. In any other case I would just nest a few ifelse statements, however, in this case i have 4*6*2*3=144 combinations and i get weird 'context overflow' errors. So I wonder if there is a more efficient way of doing this. For illustrational purposes, let's say i have: x<-c(1,0,0,1,0,0,1,0,0,1) y<-c(1,3,2,3,2,1,2,3,2,3) z<-c(1,2,1,2,1,2,1,2,1,2) d<-as.data.frame(cbind(x,y,z)) and i do: d$myvar <- ifelse(d$x == 0 & d$y==1 & d$z==1 , d$myvar <- 1, ifelse(d$x == 0 & d$y==1 & d$z==2 , d$myvar <- 2, ifelse(d$x == 0 & d$y==2 & d$z==1 , d$myvar <- 3, ifelse(d$x == 0 & d$y==2 & d$z==2 , d$myvar <- 4, ifelse(d$x == 0 & d$y==3 & d$z==1 , d$myvar <- 5, ifelse(d$x == 0 & d$y==3 & d$z==2 , d$myvar <- 6, ifelse(d$x == 1 & d$y==1 & d$z==1 , d$myvar <- 7, ifelse(d$x == 1 & d$y==1 & d$z==2 , d$myvar <- 8, ifelse(d$x == 1 & d$y==2 & d$z==1 , d$myvar <- 9, ifelse(d$x == 1 & d$y==2 & d$z==2 , d$myvar <- 10, ifelse(d$x == 1 & d$y==3 & d$z==1 , d$myvar <- 11, ifelse(d$x == 1 & d$y==3 & d$z==2 , d$myvar <- 12, NA Suggestions? __ 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] Combining all possible values of variables into a new...
try this: x <- c(1,0,0,1,0,0,1,0,0,1) y <- c(1,3,2,3,2,1,2,3,2,3) z <- c(1,2,1,2,1,2,1,2,1,2) d <- data.frame(x, y, z) ind <- do.call("paste", c(expand.grid(1:2, 1:3, 0:1)[3:1], sep = "\r")) trg <- do.call("paste", c(d, sep = "\r")) d$myvar <- match(trg, ind) I hope it helps. Best, Dimitris [EMAIL PROTECTED] wrote: I'm trying to create a new column in my data.frame where subjects are categorized depending on values on four other columns. In any other case I would just nest a few ifelse statements, however, in this case i have 4*6*2*3=144 combinations and i get weird 'context overflow' errors. So I wonder if there is a more efficient way of doing this. For illustrational purposes, let's say i have: x<-c(1,0,0,1,0,0,1,0,0,1) y<-c(1,3,2,3,2,1,2,3,2,3) z<-c(1,2,1,2,1,2,1,2,1,2) d<-as.data.frame(cbind(x,y,z)) and i do: d$myvar <- ifelse(d$x == 0 & d$y==1 & d$z==1 , d$myvar <- 1, ifelse(d$x == 0 & d$y==1 & d$z==2 , d$myvar <- 2, ifelse(d$x == 0 & d$y==2 & d$z==1 , d$myvar <- 3, ifelse(d$x == 0 & d$y==2 & d$z==2 , d$myvar <- 4, ifelse(d$x == 0 & d$y==3 & d$z==1 , d$myvar <- 5, ifelse(d$x == 0 & d$y==3 & d$z==2 , d$myvar <- 6, ifelse(d$x == 1 & d$y==1 & d$z==1 , d$myvar <- 7, ifelse(d$x == 1 & d$y==1 & d$z==2 , d$myvar <- 8, ifelse(d$x == 1 & d$y==2 & d$z==1 , d$myvar <- 9, ifelse(d$x == 1 & d$y==2 & d$z==2 , d$myvar <- 10, ifelse(d$x == 1 & d$y==3 & d$z==1 , d$myvar <- 11, ifelse(d$x == 1 & d$y==3 & d$z==2 , d$myvar <- 12, NA Suggestions? __ 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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ 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] use of empty space in split graph device
That's it. thanks Regards/Cordialement Benoit Boulinguiez -Message d'origine- De : Greg Snow [mailto:[EMAIL PROTECTED] Envoyé : vendredi 17 octobre 2008 19:19 À : Benoit Boulinguiez; r-help@r-project.org Objet : RE: [R] use of empty space in split graph device The plot.new function will start a new plot in the next frame, but not plot anything. By default the coordinates go from 0 to 1 in both the x and y directions. Try: > par(mfrow=c(2,2)) > boxplot(rnorm(100)) > boxplot(runif(100)) > boxplot(rexp(100, 1/3)) > plot.new() > legend( 0,1, pch=1:3, legend=c('a','b','c'), lty=1, > col=c('red','green','blue')) > Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] 801.408.8111 > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > project.org] On Behalf Of Benoit Boulinguiez > Sent: Friday, October 17, 2008 7:30 AM > To: r-help@r-project.org > Subject: [R] use of empty space in split graph device > > Hi all, > > I divide the graphical device into 4 ---mfrow=c(2,2)--- to plot 3 > boxplots graph. > Thus I get an empty space for the fourth graph. I d'like to place a > legend in this space. > > legend() creates a legend in the last graph (the 3rd) I'd like a > legend in the empty space. > > How may I do it? > > #graph parameter > par( fin=c(6,6), #dim graph > mai=c(1,1,0.5,0.5) #marges graph > ,mfrow=c(2,2) > ) > #boxplots > boxplot(x) > title(main=expression("1- residuals distribution")) > abline(0,0,lwd=2,col=2) > boxplot(x) > title(main=expression("2- residuals distribution")) > abline(0,0,lwd=2,col=2) > boxplot(x) > title(main=expression("3- residuals distribution")) > abline(0,0,lwd=2,col=2) > > > > Regards/Cordialement > > - > Benoit Boulinguiez > Ph.D > Ecole de Chimie de Rennes (ENSCR) Bureau 1.20 Equipe CIP UMR CNRS 6226 > "Sciences Chimiques de Rennes" > Campus de Beaulieu, 263 Avenue du Général Leclerc 35700 Rennes, France > Tel 33 (0)2 23 23 80 83 Fax 33 (0)2 23 23 81 20 http://www.ensc- > rennes.fr/ > > > > [[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] convert matrix to dataframe with repeating row names
> I have a matrix x with repeating row names. > zz<-matrix(0,4,4) > > rownames(zz)=c("a","a","b","b") > > data.frame(zz) (?) The row names on a data frame should be unique. You can try as.data.frame(xx, row.names=FALSE) to convert zz to be a data frame. If you need the row name information, add it as a column in the data frame, e.g. mydataframe$rnames <- rownames(zz). (Note to R-Core: the documentation for as.data.frame doesn't mention the usage of row.names=FALSE to ignore row names, but it seems to work consistently. Does the help page for as.data.frame need updating?) > lm(as.formula(paste("final_dat[,5]~",paste(colnames(x),collapse="+"))),x > ) > > this gives me a error > Error in model.frame.default(formula = > as.formula(paste("final_dat[,5]~", : > > 'data' must be a data.frame, not a matrix or an array I suspect that if you try class(x), it will be a matrix, not the requisite data frame. Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ 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] Combining all possible values of variables into a new...
or if x, y and z are factors : > dbis <- as.data.frame(apply(d, 2, as.factor) > dbis$x:dbis$y:dbis$z [1] 1:1:1 0:3:2 0:2:1 1:3:2 0:2:1 0:1:2 1:2:1 0:3:2 0:2:1 1:3:2 12 Levels: 0:1:1 0:1:2 0:2:1 0:2:2 0:3:1 0:3:2 1:1:1 1:1:2 1:2:1 ... 1:3:2 and for your results : > as.numeric(dbis$x:dbis$y:dbis$z) [1] 7 6 3 12 3 2 9 6 3 12 2008/10/20 Dimitris Rizopoulos <[EMAIL PROTECTED]> > try this: > > x <- c(1,0,0,1,0,0,1,0,0,1) > y <- c(1,3,2,3,2,1,2,3,2,3) > z <- c(1,2,1,2,1,2,1,2,1,2) > d <- data.frame(x, y, z) > > ind <- do.call("paste", c(expand.grid(1:2, 1:3, 0:1)[3:1], sep = "\r")) > trg <- do.call("paste", c(d, sep = "\r")) > d$myvar <- match(trg, ind) > > > I hope it helps. > > Best, > Dimitris > > > > [EMAIL PROTECTED] wrote: > >> I'm trying to create a new column in my data.frame where subjects are >> categorized depending on values on four other columns. In any other case I >> would just nest a few ifelse statements, however, in this case i have >> 4*6*2*3=144 combinations and i get weird 'context overflow' errors. So I >> wonder if there is a more efficient way of doing this. >> For illustrational purposes, let's say i have: >> >> x<-c(1,0,0,1,0,0,1,0,0,1) >> y<-c(1,3,2,3,2,1,2,3,2,3) >> z<-c(1,2,1,2,1,2,1,2,1,2) >> d<-as.data.frame(cbind(x,y,z)) >> >> and i do: >> >> d$myvar <- ifelse(d$x == 0 & d$y==1 & d$z==1 , d$myvar <- 1, >> ifelse(d$x == 0 & d$y==1 & d$z==2 , d$myvar <- 2, >> ifelse(d$x == 0 & d$y==2 & d$z==1 , d$myvar <- 3, >> ifelse(d$x == 0 & d$y==2 & d$z==2 , d$myvar <- 4, >> ifelse(d$x == 0 & d$y==3 & d$z==1 , d$myvar <- 5, >> ifelse(d$x == 0 & d$y==3 & d$z==2 , d$myvar <- 6, >> ifelse(d$x == 1 & d$y==1 & d$z==1 , d$myvar <- 7, >> ifelse(d$x == 1 & d$y==1 & d$z==2 , d$myvar <- 8, >> ifelse(d$x == 1 & d$y==2 & d$z==1 , d$myvar <- 9, >> ifelse(d$x == 1 & d$y==2 & d$z==2 , d$myvar <- 10, >> ifelse(d$x == 1 & d$y==3 & d$z==1 , d$myvar <- 11, >> ifelse(d$x == 1 & d$y==3 & d$z==2 , d$myvar <- 12, NA >> >> Suggestions? >> >> __ >> 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. >> >> > -- > Dimitris Rizopoulos > Assistant Professor > Department of Biostatistics > Erasmus Medical Center > > Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands > Tel: +31/(0)10/7043478 > Fax: +31/(0)10/7043014 > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calculate SPE in PLS package
"Stella Sim" <[EMAIL PROTECTED]> writes: > I want to calculate SPE (squared prediction error) in x-space, can > someone help? > > Here are my codes: > > fit.pls<- > plsr(Y~X,data=DAT,ncomp=3,scale=T,method='oscorespls',validation="CV",x= > T) > actual<-fit.pls$model$X (The x = TRUE is not needed as long as model = TRUE (default). x=TRUE returns the predictors as fit.pls$x, and is included for "compatibility" with lm().) > pred<-fit.pls$scores %*% t(fit.pls$loadings) > SPE.x<-rowSums((actual-pred)^2) > > Am I missing something here? You are missing the mean X spectrum. See matplot(t(pred), type = "l", lty = 1) vs. matplot(t(actual), type = "l", lty = 1) The Xmeans compontent of fit.pls contains this, so pred <- sweep(fit.pls$scores %*% t(fit.pls$loadings), 2, fit.pls$Xmeans, "+") would give you what you want. Note, however, that this will calculate the _fitted_ SPE, not the cross-validated SPE. The crossvalidation implemented in the pls package does not save the cross-validated scores/loadings -- that would consume too much memory. (Calculation of SPE withing the cross-validation routines could have been implemented, but was not.) -- Regards, Bjørn-Helge Mevik __ 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] Combining all possible values of variables into a new...
On Mon, Oct 20, 2008 at 4:10 PM, <[EMAIL PROTECTED]> wrote: > > I'm trying to create a new column in my data.frame where subjects are > categorized depending on values on four other columns. In any other case I > would just nest a few ifelse statements, however, in this case i have > 4*6*2*3=144 combinations and i get weird 'context overflow' errors. So I > wonder if there is a more efficient way of doing this. > > For illustrational purposes, let's say i have: > > x<-c(1,0,0,1,0,0,1,0,0,1) > y<-c(1,3,2,3,2,1,2,3,2,3) > z<-c(1,2,1,2,1,2,1,2,1,2) > d<-as.data.frame(cbind(x,y,z)) > > and i do: > > d$myvar <- ifelse(d$x == 0 & d$y==1 & d$z==1 , d$myvar <- 1, > ifelse(d$x == 0 & d$y==1 & d$z==2 , d$myvar <- 2, > ifelse(d$x == 0 & d$y==2 & d$z==1 , d$myvar <- 3, > ifelse(d$x == 0 & d$y==2 & d$z==2 , d$myvar <- 4, > ifelse(d$x == 0 & d$y==3 & d$z==1 , d$myvar <- 5, > ifelse(d$x == 0 & d$y==3 & d$z==2 , d$myvar <- 6, > ifelse(d$x == 1 & d$y==1 & d$z==1 , d$myvar <- 7, > ifelse(d$x == 1 & d$y==1 & d$z==2 , d$myvar <- 8, > ifelse(d$x == 1 & d$y==2 & d$z==1 , d$myvar <- 9, > ifelse(d$x == 1 & d$y==2 & d$z==2 , d$myvar <- 10, > ifelse(d$x == 1 & d$y==3 & d$z==1 , d$myvar <- 11, > ifelse(d$x == 1 & d$y==3 & d$z==2 , d$myvar <- 12, NA > > Suggestions? How about the following? x<-c(1,0,0,1,0,0,1,0,0,1) y<-c(1,3,2,3,2,1,2,3,2,3) z<-c(1,2,1,2,1,2,1,2,1,2) d<-as.data.frame(cbind(x,y,z)) xyz.comb<-interaction(x,y,z,lex.order=T) d$myvar<-match(xyz.comb,levels(xyz.comb)) /Gustaf Gustaf Rydevik, M.Sci. tel: +46(0)703 051 451 address:Essingetorget 40,112 66 Stockholm, SE skype:gustaf_rydevik __ 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] Odp: Combining all possible values of variables into a new...
Hi maybe you can change combination of your columns to factor new <-factor(paste(x,y,z, sep="")) and then reorder this factor (see reorder) change it to numeric to get index index <- as.numeric(factor) and then choose from set of 144 data data[index] or use your index directly if you need just numbers from 1 to the final to get your myvar. Maybe you could also look to permutations function from gtools package Regards Petr [EMAIL PROTECTED] napsal dne 20.10.2008 16:10:26: > > I'm trying to create a new column in my data.frame where subjects are > categorized depending on values on four other columns. In any other case I > would just nest a few ifelse statements, however, in this case i have > 4*6*2*3=144 combinations and i get weird 'context overflow' errors. So I > wonder if there is a more efficient way of doing this. > > For illustrational purposes, let's say i have: > > x<-c(1,0,0,1,0,0,1,0,0,1) > y<-c(1,3,2,3,2,1,2,3,2,3) > z<-c(1,2,1,2,1,2,1,2,1,2) > d<-as.data.frame(cbind(x,y,z)) > > and i do: > > d$myvar <- ifelse(d$x == 0 & d$y==1 & d$z==1 , d$myvar <- 1, > ifelse(d$x == 0 & d$y==1 & d$z==2 , d$myvar <- 2, > ifelse(d$x == 0 & d$y==2 & d$z==1 , d$myvar <- 3, > ifelse(d$x == 0 & d$y==2 & d$z==2 , d$myvar <- 4, > ifelse(d$x == 0 & d$y==3 & d$z==1 , d$myvar <- 5, > ifelse(d$x == 0 & d$y==3 & d$z==2 , d$myvar <- 6, > ifelse(d$x == 1 & d$y==1 & d$z==1 , d$myvar <- 7, > ifelse(d$x == 1 & d$y==1 & d$z==2 , d$myvar <- 8, > ifelse(d$x == 1 & d$y==2 & d$z==1 , d$myvar <- 9, > ifelse(d$x == 1 & d$y==2 & d$z==2 , d$myvar <- 10, > ifelse(d$x == 1 & d$y==3 & d$z==1 , d$myvar <- 11, > ifelse(d$x == 1 & d$y==3 & d$z==2 , d$myvar <- 12, NA > > Suggestions? > > __ > 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] Extracting variables with a given prefix in the parent environment
Thank you all for your answers. On Mon, Oct 20, 2008 at 6:32 AM, Henrique Dallazuanna <[EMAIL PROTECTED]>wrote: > Try this: > > Using 'envir' argument, in ls and get function: > > get.vars.name.prefix<-function(prefix, envir = parent.frame()){ >result<-list() >len<-nchar(prefix) >var.names<-ls(envir = envir,pattern=prefix) >print(var.names) >for(i in 1:length(var.names)){ > name<-var.names[i] > field<-substr(name,len+1,nchar(name)) > result[[field]]<-get(name, envir = envir) > } > result > } > > On Mon, Oct 20, 2008 at 4:06 AM, erwann rogard <[EMAIL PROTECTED]>wrote: > >> hi, >> >> get.vars.name.prefix<-function(prefix){ >> result<-list() >> len<-nchar(prefix) >> var.names<-ls(name=1,pattern=prefix) #name=1 probably wrong option >> print(var.names) >> for(i in 1:length(var.names)){ >> name<-var.names[i] >> field<-substr(name,len+1,nchar(name)) >> result[[field]]<-get(name) >> } >> result >> } >> >> for example >> x.1<-1 >> x.2<-2 >> get.vars.name.prefix("x.") should return 1,2 >> >> this does not work if i call if from within another function: >> >> g<-function(){ >> x.1<-1 >> x.2<-2 >> get.vars.name.prefix("x.") # should return 1,2, nothing else >> } >> >> i would like the environment specified within ls(...) to be that of the >> body >> of the function that calls get.vars.name.prefix. apparently name=1 is >> probably not the right option. >> >> thanks. >> >>[[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. >> > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O > [[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] Row Sampling
Hi everyone, does any one knows how can I make sample from rows? i.e. I have a data like this: s1 s2 s3 s4 1 0 0 0 1 2 1 0 1 0 3 0 0 0 0 4 0 0 0 0 5 0 1 0 1 6 1 0 0 0 7 0 0 0 0 8 0 0 0 0 9 0 0 0 0 10 0 0 0 1 I need to make 5 different sample with 5 different persons(rows) in each sample from it keeping s1,s3,s3,s4 but changing rows. I cant get "replicate" or "sample" functions to make samples by changing the rows. Thanks -- View this message in context: http://www.nabble.com/Row-Sampling-tp20067830p20067830.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] Row Sampling
Is this what you want: > x <- read.table(textConnection(" s1 s2 s3 s4 + 1 0 0 0 1 + 2 1 0 1 0 + 3 0 0 0 0 + 4 0 0 0 0 + 5 0 1 0 1 + 6 1 0 0 0 + 7 0 0 0 0 + 8 0 0 0 0 + 9 0 0 0 0 + 10 0 0 0 1"), header=TRUE) > closeAllConnections() > for (i in 1:5){ # take 5 samples + print(x[sample(nrow(x), 5),]) + } s1 s2 s3 s4 7 0 0 0 0 4 0 0 0 0 3 0 0 0 0 10 0 0 0 1 9 0 0 0 0 s1 s2 s3 s4 3 0 0 0 0 2 1 0 1 0 4 0 0 0 0 7 0 0 0 0 8 0 0 0 0 s1 s2 s3 s4 10 0 0 0 1 7 0 0 0 0 3 0 0 0 0 4 0 0 0 0 1 0 0 0 1 s1 s2 s3 s4 1 0 0 0 1 7 0 0 0 0 10 0 0 0 1 4 0 0 0 0 9 0 0 0 0 s1 s2 s3 s4 10 0 0 0 1 5 0 1 0 1 4 0 0 0 0 2 1 0 1 0 9 0 0 0 0 On Mon, Oct 20, 2008 at 10:00 AM, Alex99 <[EMAIL PROTECTED]> wrote: > > > Hi everyone, > does any one knows how can I make sample from rows? > i.e. I have a data like this: > > s1 s2 s3 s4 > 1 0 0 0 1 > 2 1 0 1 0 > 3 0 0 0 0 > 4 0 0 0 0 > 5 0 1 0 1 > 6 1 0 0 0 > 7 0 0 0 0 > 8 0 0 0 0 > 9 0 0 0 0 > 10 0 0 0 1 > > I need to make 5 different sample with 5 different persons(rows) in each > sample from it keeping s1,s3,s3,s4 but changing rows. I cant get "replicate" > or "sample" functions to make samples by changing the rows. > > Thanks > > -- > View this message in context: > http://www.nabble.com/Row-Sampling-tp20067830p20067830.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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Combining all possible values of variables into a new...
yet another way (as it always is in R): > x<-c(1,0,0,1,0,0,1,0,0,1) > y<-c(1,3,2,3,2,1,2,3,2,3) > z<-c(1,2,1,2,1,2,1,2,1,2) > d<-as.data.frame(cbind(x,y,z)) > d$myvar <- x*6 + (y-1)*2 + z > > d x y z myvar 1 1 1 1 7 2 0 3 2 6 3 0 2 1 3 4 1 3 212 5 0 2 1 3 6 0 1 2 2 7 1 2 1 9 8 0 3 2 6 9 0 2 1 3 10 1 3 212 On Mon, Oct 20, 2008 at 10:10 AM, <[EMAIL PROTECTED]> wrote: > > I'm trying to create a new column in my data.frame where subjects are > categorized depending on values on four other columns. In any other case I > would just nest a few ifelse statements, however, in this case i have > 4*6*2*3=144 combinations and i get weird 'context overflow' errors. So I > wonder if there is a more efficient way of doing this. > > For illustrational purposes, let's say i have: > > x<-c(1,0,0,1,0,0,1,0,0,1) > y<-c(1,3,2,3,2,1,2,3,2,3) > z<-c(1,2,1,2,1,2,1,2,1,2) > d<-as.data.frame(cbind(x,y,z)) > > and i do: > > d$myvar <- ifelse(d$x == 0 & d$y==1 & d$z==1 , d$myvar <- 1, > ifelse(d$x == 0 & d$y==1 & d$z==2 , d$myvar <- 2, > ifelse(d$x == 0 & d$y==2 & d$z==1 , d$myvar <- 3, > ifelse(d$x == 0 & d$y==2 & d$z==2 , d$myvar <- 4, > ifelse(d$x == 0 & d$y==3 & d$z==1 , d$myvar <- 5, > ifelse(d$x == 0 & d$y==3 & d$z==2 , d$myvar <- 6, > ifelse(d$x == 1 & d$y==1 & d$z==1 , d$myvar <- 7, > ifelse(d$x == 1 & d$y==1 & d$z==2 , d$myvar <- 8, > ifelse(d$x == 1 & d$y==2 & d$z==1 , d$myvar <- 9, > ifelse(d$x == 1 & d$y==2 & d$z==2 , d$myvar <- 10, > ifelse(d$x == 1 & d$y==3 & d$z==1 , d$myvar <- 11, > ifelse(d$x == 1 & d$y==3 & d$z==2 , d$myvar <- 12, NA > > Suggestions? > > __ > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] Combining all possible values of variables into a new...
On Mon, Oct 20, 2008 at 11:14 AM, jim holtman <[EMAIL PROTECTED]> wrote: > yet another way (as it always is in R): > >> x<-c(1,0,0,1,0,0,1,0,0,1) >> y<-c(1,3,2,3,2,1,2,3,2,3) >> z<-c(1,2,1,2,1,2,1,2,1,2) >> d<-as.data.frame(cbind(x,y,z)) >> d$myvar <- x*6 + (y-1)*2 + z >> >> d > x y z myvar > 1 1 1 1 7 > 2 0 3 2 6 > 3 0 2 1 3 > 4 1 3 212 > 5 0 2 1 3 > 6 0 1 2 2 > 7 1 2 1 9 > 8 0 3 2 6 > 9 0 2 1 3 > 10 1 3 212 That's equivalent to as.numeric(interaction(x, y, z)) but in my experience is much much faster (which of course only matters for huge datasets). Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to get estimate of confidence interval?
I thought I was finished, having gotten everything to work as intended. This is a model of risk, and the short term forecasts look very good, given the data collected after the estimates are produced (this model is intended to be executed daily, to give a continuing picture of our risk). But now there is a new requirement. I have weekly samples from a non-autonomous process (i.e. although well modelled as a decay process, with an exponential distribution fitting the decay times well, the rate estimates and their sd vary considerably from one week to the next). The total number of events to be expected from a given sample over the next week can be easily estimated from a simple integral. And the total number of these events from all samples, is just the sum of these estimates over all samples. So far, so good (imagine you have a sample of a variety of species of radionuclides all emitting alpha particles with the same energy - so you can't tell from the decay event which species produced the alpha particles). I guess there are two parts of my question. I get a fit of the exponential distribution to each sample using fitdistr(x,"exponential"). I am finding the expected values vary by as much as a factor of 4, and the corresponding estimates of sd vary by as much as a factor of 100 (some samples are MUCH larger than others). How do I go from the sd it gives to a 99% confidence interval for the integral for that function from now through a week from now (or to the end of time, or through the next month/quarter)? And how do I move from these estimates to get the expected value and confidence intervals for the totals over all the samples? I am a bit rusty on figuring out how error propagates through model calculations (an online reference for this would be handy, if you know of one). Thanks Ted -- View this message in context: http://www.nabble.com/How-to-get-estimate-of-confidence-interval--tp20073921p20073921.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] Zero mean correlation Matrix
Hi,, I want to use the existing cor function in R but with a different way to compute the correlation method.. basically zero mean correlation. The forumula I have is 'D' <- function(c1, c2) sum(c1*c2, na.rm=T)/(sqrt(sum(c1*c1, na.rm=T))*sqrt(sum(c2*c2, na.rm=T))) I am not sure how i can modify the method cor computes its square roots and covariance matrixes? I only need to add this to get the answer -- View this message in context: http://www.nabble.com/Zero-mean-correlation-Matrix-tp20074044p20074044.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] slow graphics download
Hi, I often work from home, running R on my office computer and displaying interactive graphics on my home computer using X11. This was always more sluggish than sitting at my office computer, obviously, but recently the graphics transfer has become painfully slow -- so slow, that I now divert the images to a postscript file and display that file remotely (which takes a second or two). I don't know what changed between the old days and now -- I may have installed a new version of R and updated the o.s. (ubuntu) on both computers, but am unsure of the timing. I realize this makes troubleshooting difficult, but I am hoping someone can offer a tip on where to begin. Thanks -Paul __ 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] folded normal distribution in R
Dear R useRs, i wanted to ask if the folded normal destribution (Y = abs(X) with X normal distributed) with density and random number generator is implemented in R or in any R-related package so far? Maybe i can use the non-central chi-square distribution and rchisq(n, df=1, ncp>0) here? Thanks and best regards Andreas __ 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] slow graphics download
I suspect that you need to set the type= in X11(): see its help page. E.g. 'type = "nbcairo"' is the same device as 'type="cairo"' without buffering: which is faster will depend on the X11 connection. Both will be slower than 'type = "Xlib"', especially on a slow X11 connection as all the rendering is done on the machine running R rather than in the X server. Basically, R's X11 device is now by default optimized for quality rather than speed, and your unusual usage needs the reverse. On Mon, 20 Oct 2008, Paul Murtaugh wrote: Hi, I often work from home, running R on my office computer and displaying interactive graphics on my home computer using X11. This was always more sluggish than sitting at my office computer, obviously, but recently the graphics transfer has become painfully slow -- so slow, that I now divert the images to a postscript file and display that file remotely (which takes a second or two). I don't know what changed between the old days and now -- I may have installed a new version of R and updated the o.s. (ubuntu) on both computers, but am unsure of the timing. I realize this makes troubleshooting difficult, but I am hoping someone can offer a tip on where to begin. Thanks -Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] folded normal distribution in R
Dear Andreas, try: library(distr) X <- Norm() ## standard normal distribution Y <- abs(X) plot(Y) Best regards, Matthias Andreas Wittmann wrote: Dear R useRs, i wanted to ask if the folded normal destribution (Y = abs(X) with X normal distributed) with density and random number generator is implemented in R or in any R-related package so far? Maybe i can use the non-central chi-square distribution and rchisq(n, df=1, ncp>0) here? Thanks and best regards Andreas __ 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. -- Dr. Matthias Kohl www.stamats.de __ 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] folded normal distribution in R
It's trivial to do. In particular abs(rnorm(...)) will give you the random number generator. The term 'folded normal distribution' is normally only used for mean=0, when you just double the density, but the general result is ifelse(x > 0, 1, 0) * (dnorm(x, ...) + dnorm(-x, ...)) On Mon, 20 Oct 2008, Andreas Wittmann wrote: Dear R useRs, i wanted to ask if the folded normal destribution (Y = abs(X) with X normal distributed) with density and random number generator is implemented in R or in any R-related package so far? Maybe i can use the non-central chi-square distribution and rchisq(n, df=1, ncp>0) here? Thanks and best regards Andreas -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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 Newbie Question
Hello list, I just started R today and tried something quite simple. I wanted to create a colored plot and eventually after hours of fiddling around got it working. However, my solution seems very suboptimal and I'd really appreciate your hints on how to improve. I believe that R already offers many functions I coded (e.g. distance between two vectors, vector length, vector normalization and so on). I generally didn't even figure out how to create a simple vector or how to extract a row from a matrix so the result is a vector (to get scalars, I use the "sum" functions, which is an incredibly ugly workaround). To sum the problem up: one has a binary star system with a large star (e.g. red giant) and a small star (e.g. white dwarf). Gravitation between them is directly proportional to the mass and indirectly proportional to the square of the distance. If correctly plotted, one should be able to see the inner lagrange point L1 which is the point where the gravitational potentials of the stars "cancel out", e.g. an object would not be attracted to any star. Well, enough background information, here's my rookie code - please feel free to comment on anything :-) Kind regards, Johannes star1center = vector("numeric", 2) star1center[1] = -0.5 star1center[2] = 0 star1mass = 30 star2center = vector("numeric", 2) star2center[1] = 0.5 star2center[2] = 0 star2mass = 1 sqr = function(x) { return(x * x) } distance = function(a, b) { return(sqrt(sqr(a[1] - b[1]) + sqr(a[2] - b[2]))) } len = function(x) { return(sqrt(sqr(x[1]) + sqr(x[2]))) } norm = function(x) { return(x / len(x)) } gravitation = function(invecx, invecy) { invec = vector("numeric", 2) invec[1] = invecx invec[2] = invecy vec1 = star1mass * norm(star1center - invec) / sqr(distance(invec, star1center)) vec2 = star2mass * norm(star2center - invec) / sqr(distance(invec, star2center)) return(len(vec1 + vec2)) } vmin = -1 vmax = 1 step = 0.1 vals = ((vmax - vmin) / step) + 1 xvals = seq(vmin, vmax, step) yvals = seq(vmin, vmax, step) a = expand.grid(seq(vmin, vmax, step), seq(vmin, vmax, step)) b = matrix(seq(1, vals*vals), vals) for (x in 1:vals) { for (y in 1:vals) { b[x, y] = gravitation(sum(a[x,][1]), sum(a[y,][1])) } } filled.contour(xvals, yvals, z = b, color = heat.colors, ylim = c(-1, 1), xlim = c(-1, 1), zlim = c(0, 100), nlevels = 100) __ 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] pass longer arguments to adj of text()
Hi, text()'s pos does handle more dimensional labels, while adj does not - or how can I pass an array to text() and use the adj argument (skyblue text)? plot(-1:1,-1:1) text(c(0,0),c(0,0),c("a","b"),pos=c(1,2),col="red") text(c(0,0),c(0,0),c("a","b"),adj=cbind(c(1,2),c(1,1)),col="skyblue") Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error message when plotting survival curves
I am trying to plot survival curves using the following code as an example: >rs1799964.coxph<-(coxph(Surv(sassurvmonths,status)~age+stage+rs1799964_TNFA,method="efron")) >plot(rs1799964.coxph,lyt=c(1,3),xlab="Survival in Months",ylab="Proportion Surviving") I am gettingthe following error message: >Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ Any input to debugging this matter would be greatly appreciated. Thank you in advance. -Alison -- View this message in context: http://www.nabble.com/error-message-when-plotting-survival-curves-tp20075771p20075771.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] distributions and glm
Hello, I have seen that some papers do this: 1.) Group data by year (e.g. 35 years) 2.) Estimate the mean of the key variable through the distribution that fits better (some years is a normal distribution , others is a more skewed, gamma distribution, etc.) 3.) With these estimated means of each year do a GLM. I'd like to know if it is possible (to use these means in a GLM) or is a wrong idea. Thanks in advance David -- View this message in context: http://www.nabble.com/distributions-and-glm-tp20075826p20075826.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] calculating mean for samples
Hi everyone, > does any one knows how can I calculate mean for different samples > i.e. I have a data like this: > > s1 s2 s3 s4 > 1 0 0 0 1 > 2 1 0 1 0 > 3 0 0 0 0 > 4 0 0 0 0 > 5 0 1 0 1 > 6 1 0 0 0 > 7 0 0 0 0 > 8 0 0 0 0 > 9 0 0 0 0 > 10 0 0 0 1 > > I need to make 5 different sample with 5 different persons(rows) in each > sample from it keeping s1,s3,s3,s4 but changing rows. and then calculate > the mean for each "S" in each sample. and finally calculate the grand > mean,which is the mean of means for each sample. i.e. if I sample 5 time I > get 5 different means for s1, s2, s3, s4. then I need to add all five > means for and divide it by 5.(of course I have to do it for s1,s2,s3,s4 > separately) -- View this message in context: http://www.nabble.com/calculating-mean-for-samples-tp20075174p20075174.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] Staging area for data before read into R
I am wondering if there is a better alternative than Excel for data storage that does not require database knowledge (I will eventually have to learn this, but it is not on my immediate todo list). I need something that is not limited to 256 columns... I don't need any of the built in functions in excel just a spreadsheet like program with cells that hold data in a data.frame format for a staging area before I get it into R. Any help would be greatly appreciated. This is not a direct r question, but all of you folks have more experience than I do and I am having a time finding what I need with google. thanks in advance -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ 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] error message when plotting survival curves
I believe that you have to specify which variable is the x and also the y. I am not familiar with what you are doing, but it looks as though you need to specify both x and y to get it to plot. Stephen On Mon, Oct 20, 2008 at 2:22 PM, A Van Dyke <[EMAIL PROTECTED]> wrote: > > I am trying to plot survival curves using the following code as an example: > >>rs1799964.coxph<-(coxph(Surv(sassurvmonths,status)~age+stage+rs1799964_TNFA,method="efron")) > >>plot(rs1799964.coxph,lyt=c(1,3),xlab="Survival in Months",ylab="Proportion > Surviving") > > I am gettingthe following error message: > > >>Error in xy.coords(x, y, xlabel, ylabel, log) : > 'x' and 'y' lengths differ > > > Any input to debugging this matter would be greatly appreciated. Thank you > in advance. > > -Alison > -- > View this message in context: > http://www.nabble.com/error-message-when-plotting-survival-curves-tp20075771p20075771.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. > -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R Newbie Question
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Johannes Bauer > Sent: Monday, October 20, 2008 10:42 AM > To: r-help@r-project.org > Subject: [R] R Newbie Question > > Hello list, > > I just started R today and tried something quite simple. I wanted to > create a colored plot and eventually after hours of fiddling > around got > it working. However, my solution seems very suboptimal and I'd really > appreciate your hints on how to improve. I believe that R > already offers > many functions I coded (e.g. distance between two vectors, vector > length, vector normalization and so on). I generally didn't > even figure > out how to create a simple vector See ?c (i.e. type "?c" without quotes at R prompt) star1center = c(-0.5, 0) or how to extract a row > from a matrix > so the result is a vector (to get scalars, I use the "sum" functions, > which is an incredibly ugly workaround). In your code a[] is not a matrix, it is a data frame. However, you should be able to index it just like you would a matrix. For your code, b[x, y] = gravitation(a[x,1], a[y,1]) Without the need for the sum() function. > > To sum the problem up: one has a binary star system with a large star > (e.g. red giant) and a small star (e.g. white dwarf). Gravitation > between them is directly proportional to the mass and indirectly > proportional to the square of the distance. If correctly plotted, one > should be able to see the inner lagrange point L1 which is the point > where the gravitational potentials of the stars "cancel out", e.g. an > object would not be attracted to any star. Well, enough background > information, here's my rookie code - please feel free to comment on > anything :-) > > Kind regards, > Johannes > > > <<>> I have edited your code to simplify some of your functions and use vectorized computations. I'm sure others could provide even more optimized code. I will leave it to others to respond concerning already written functions for norm, len, etc. You could try using the various search functions with key terms (like distance) to see what may be available. star1center = c(-0.5, 0) star1mass = 30 star2center = c(0.5, 0) star2mass = 1 sqr = function(x) { return(x * x) } distance = function(a, b) { return(sum((a-b)^2)^0.5) } len = function(x) { return(sum(x^2)^0.5) } norm = function(x) { return(x / len(x)) } gravitation = function(invecx, invecy) { invec = c(invecx, invecy) vec1 = star1mass * norm(star1center - invec) / sqr(distance(invec,star1center)) vec2 = star2mass * norm(star2center - invec) / sqr(distance(invec,star2center)) return(len(vec1 + vec2)) } vmin = -1 vmax = 1 step = 0.1 vals = ((vmax - vmin) / step) + 1 xvals = seq(vmin, vmax, step) yvals = seq(vmin, vmax, step) a = expand.grid(seq(vmin, vmax, step), seq(vmin, vmax, step)) b = matrix(seq(1, vals*vals), vals) for (x in 1:vals) { for (y in 1:vals) { b[x, y] = gravitation(a[x,1], a[y,1]) } } filled.contour(xvals, yvals, z = b, color = heat.colors, ylim = c(-1, 1), xlim = c(-1, 1), zlim = c(0, 100), nlevels = 100) Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ 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] calculating mean for samples
assuming that A1 is the data provided in the first post... it would be helpful if you used dput() to copy into an email, so that we could just copy the code and data right into a R session and be off and running. I hope this helps. #I used dput() on the object A1 A1 <- (structure(list(s1 = c(0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L), s2 = c(0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L), s3 = c(0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), s4 = c(1L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 1L)), .Names = c("s1", "s2", "s3", "s4" ), class = "data.frame", row.names = c(NA, -10L))) f <- do.call(rbind , rep(A1[sample(nrow(A1), 5),], 5)) d <- apply(f, MARGIN=1, FUN=mean) mean(d[names(d)==s1]) mean(d[names(d)==s2]) mean(d[names(d)==s3]) mean(d[names(d)==s4]) On Mon, Oct 20, 2008 at 2:44 PM, al ex <[EMAIL PROTECTED]> wrote: > I dont have a problem with sampling and calculating mean: > > for(i in 1:5){ > res=(A1[sample(nrow(A1), 5),]) > Avg=colMeans(res) > STD=sd(res) > print(res) > print(Avg) > print(STD) > } > > my problem is how to save the mean for each "S" in each sample and calculate > the grand mean > > > > --- On Mon, 10/20/08, stephen sefick <[EMAIL PROTECTED]> wrote: > > From: stephen sefick <[EMAIL PROTECTED]> > Subject: Re: [R] calculating mean for samples > To: "Alex99" <[EMAIL PROTECTED]> > Date: Monday, October 20, 2008, 11:34 AM > > look at > ?sample > ?lapply > ?mean > > On Mon, Oct 20, 2008 at 1:53 PM, Alex99 <[EMAIL PROTECTED]> wrote: >> >> > Hi everyone, >>> does any one knows how can I calculate mean for different samples >>> i.e. I have a data like this: >>> >>> s1 s2 s3 s4 >>> 1 0 0 0 1 >>> 2 1 0 1 0 >>> 3 0 0 0 0 >>> 4 0 0 0 0 >>> 5 0 1 0 1 >>> 6 1 0 0 0 >>> 7 0 0 0 0 >>> 8 0 0 0 0 >>> 9 0 0 0 0 >>> 10 0 0 0 1 >>> >>> I need to make 5 different sample with 5 different persons(rows) in > each >>> sample from it keeping s1,s3,s3,s4 but changing rows. and then > calculate >>> the mean for each "S" in each sample. and finally calculate > the grand >>> mean,which is the mean of means for each sample. i.e. if I sample 5 > time I >>> get 5 different means for s1, s2, s3, s4. then I need to add all five >>> means for and divide it by 5.(of course I have to do it > for > s1,s2,s3,s4 >>> separately) >> -- >> View this message in context: > http://www.nabble.com/calculating-mean-for-samples-tp20075174p20075174.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. >> > > > > -- > Stephen Sefick > Research Scientist > Southeastern Natural Sciences Academy > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > > -K. > Mullis > > __ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ 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] Staging area for data before read into R
You didn't say which version of Excel you are using but Excel 2007 allows 16,384 columns. On Mon, Oct 20, 2008 at 2:27 PM, stephen sefick <[EMAIL PROTECTED]> wrote: > I am wondering if there is a better alternative than Excel for data > storage that does not require database knowledge (I will eventually > have to learn this, but it is not on my immediate todo list). I need > something that is not limited to 256 columns... I don't need any of > the built in functions in excel just a spreadsheet like program with > cells that hold data in a data.frame format for a staging area before > I get it into R. Any help would be greatly appreciated. This is not > a direct r question, but all of you folks have more experience than I > do and I am having a time finding what I need with google. > thanks in advance > > -- > Stephen Sefick > Research Scientist > Southeastern Natural Sciences Academy > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > >-K. Mullis > > __ > 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] pass longer arguments to adj of text()
...and the offset argument can't handle arrays either: text(c(0,0),c(0,0),c("a","b"),pos=c(1,2),offset=c(1,0.5),col="darkgreen") The second argument does not have any effect. Can I pass arrays to text and use diffent locations? Thomas PS: I use R version 2.5.0 (2007-04-23) under Win2000. __ 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] Staging area for data before read into R
sorry excel 2003 with no immediate update in the future. On Mon, Oct 20, 2008 at 3:12 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > You didn't say which version of Excel you are using but Excel 2007 > allows 16,384 columns. > > On Mon, Oct 20, 2008 at 2:27 PM, stephen sefick <[EMAIL PROTECTED]> wrote: >> I am wondering if there is a better alternative than Excel for data >> storage that does not require database knowledge (I will eventually >> have to learn this, but it is not on my immediate todo list). I need >> something that is not limited to 256 columns... I don't need any of >> the built in functions in excel just a spreadsheet like program with >> cells that hold data in a data.frame format for a staging area before >> I get it into R. Any help would be greatly appreciated. This is not >> a direct r question, but all of you folks have more experience than I >> do and I am having a time finding what I need with google. >> thanks in advance >> >> -- >> Stephen Sefick >> Research Scientist >> Southeastern Natural Sciences Academy >> >> Let's not spend our time and resources thinking about things that are >> so little or so large that all they really do for us is puff us up and >> make us feel like gods. We are mammals, and have not exhausted the >> annoying little problems of being mammals. >> >>-K. Mullis >> >> __ >> 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. >> > -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ 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] par(mfrow=c(2,4))
Hi All, I'm going to draw 8 plots in one page. I want the plots to be arranged in two rows, each row has 4 plots. So, I set the it par(mfrow=c(2,4)). However, there might be too many plots in a page, all the 8 plots were drawn in triangular shape, which makes the x-y coordinate scale not in same length, the x-axis length is much shorter than the y-axis length. Could anybody let me know how to make the x-y coordinate length be the same, like the square box? Thanks in advance. Sityee __ 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] pass longer arguments to adj of text()
Why do you expect this to be vectorized when the help page clearly says otherwise? See adj: one or two values in [0,1] which specify the x (and optionally y) adjustment of the labels. On most devices values outside that interval will also work. What is wrong with two or more text() calls? NB: library(fortunes); fortune("WTFM") applies. On Mon, 20 Oct 2008, Thomas Steiner wrote: Hi, text()'s pos does handle more dimensional labels, while adj does not - or how can I pass an array to text() and use the adj argument (skyblue text)? plot(-1:1,-1:1) text(c(0,0),c(0,0),c("a","b"),pos=c(1,2),col="red") text(c(0,0),c(0,0),c("a","b"),adj=cbind(c(1,2),c(1,1)),col="skyblue") Thomas -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] error message when plotting survival curves
On Mon, 20 Oct 2008, A Van Dyke wrote: I am trying to plot survival curves using the following code as an example: rs1799964.coxph<-(coxph(Surv(sassurvmonths,status)~age+stage+rs1799964_TNFA,method="efron")) plot(rs1799964.coxph,lyt=c(1,3),xlab="Survival in Months",ylab="Proportion Surviving") You can't plot a coxph object. You probably want plot(survfit(rs1799965.copxh)) -thomas I am gettingthe following error message: Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ Any input to debugging this matter would be greatly appreciated. Thank you in advance. -Alison -- View this message in context: http://www.nabble.com/error-message-when-plotting-survival-curves-tp20075771p20075771.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. Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle __ 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] par(mfrow=c(2,4))
reproducible code please. On Mon, Oct 20, 2008 at 3:22 PM, phoebe kong <[EMAIL PROTECTED]> wrote: > Hi All, > > I'm going to draw 8 plots in one page. I want the plots to be arranged > in two rows, each row has 4 plots. So, I set the it par(mfrow=c(2,4)). > > However, there might be too many plots in a page, all the 8 plots were > drawn in triangular shape, which makes the x-y coordinate scale not in > same length, the x-axis length is much shorter than the y-axis length. > > Could anybody let me know how to make the x-y coordinate length be the > same, like the square box? > > > Thanks in advance. > Sityee > > __ > 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. > -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R 2.8.0 is released
I'm getting a unexpected compiling error when doing make: gcc -std=gnu99 -I../../src/extra/zlib -I../../src/extra/bzip2 -I../../src/extra/pcre -I. -I../../src/include -I../../src/include -I/usr/local/include -DHAVE_CONFIG_H -fpic -g -O2 -c platform.c -o platform.o platform.c: In function 'do_capabilities': platform.c:1661: error: expected ',' or ';' before 'Rf_checkArityCall' make[3]: *** [platform.o] Error 1 R.2.7.2 compiled without any problems on the same machine. Here is my config.log: http://jeroen.xslhosting.net/config.log.zip Am I doing anything wrong? And will their be binary Debian packages for this release (they never appeared for R-2.7.2)? thank you! -- View this message in context: http://www.nabble.com/R-2.8.0-is-released-tp20066170p20078192.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] R 2.8.0 is released
I'm getting a unexpected compiling error when doing make: gcc -std=gnu99 -I../../src/extra/zlib -I../../src/extra/bzip2 -I../../src/extra/pcre -I. -I../../src/include -I../../src/include -I/usr/local/include -DHAVE_CONFIG_H -fpic -g -O2 -c platform.c -o platform.o platform.c: In function 'do_capabilities': platform.c:1661: error: expected ',' or ';' before 'Rf_checkArityCall' make[3]: *** [platform.o] Error 1 R.2.7.2 compiled without any problems on the same machine. Here is my config.log: http://jeroen.xlshosting.net/config.log.zip Am I doing anything wrong? And will their be binary Debian packages for this release (they never appeared for R-2.7.2)? thank you! -- View this message in context: http://www.nabble.com/R-2.8.0-is-released-tp20066170p20078229.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] pass longer arguments to adj of text()
Brian, thank you for your reply. > Why do you expect this to be vectorized when the help page clearly says > otherwise? Sure, it's in line with the help, no problem there. I just asked if this feature is somehow possible. I expected it, because "pos" does take arrays and it "overrides any adj value given" (see help). So if "pos" does, why not "adj"? > What is wrong with two or more text() calls? it's quicker and more beautiful. See my code at the end (last loop) of http://commons.wikimedia.org/wiki/Image:Sonnenstand.png Thomas > NB: library(fortunes); fortune("WTFM") applies. This one I didn't get. They help to do it without a loop? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R 2.8.0 is released
On 10/20/2008 4:34 PM, Jeroen Ooms wrote: I'm getting a unexpected compiling error when doing make: gcc -std=gnu99 -I../../src/extra/zlib -I../../src/extra/bzip2 -I../../src/extra/pcre -I. -I../../src/include -I../../src/include -I/usr/local/include -DHAVE_CONFIG_H -fpic -g -O2 -c platform.c -o platform.o platform.c: In function 'do_capabilities': platform.c:1661: error: expected ',' or ';' before 'Rf_checkArityCall' make[3]: *** [platform.o] Error 1 R.2.7.2 compiled without any problems on the same machine. Here is my config.log: http://jeroen.xslhosting.net/config.log.zip Am I doing anything wrong? And will their be binary Debian packages for this release (they never appeared for R-2.7.2)? If you look at the file, it appears someone forgot a semicolon at the end of line 1657, which is only compiled for people on Unix with no X11. That's likely a configuration problem, e.g. you don't have the X11 development libraries installed, or the configure script couldn't find them. Duncan Murdoch __ 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] Staging area for data before read into R
Define "better". Really, it depends on what you need to do (are all your data appropriately represented in a 2D array?) and what resources are available. If all your data can be represented using a 2D array, then Excel is probably your best bet for th enear term. If not, you might as well bite the bullit and learn to use an RDBMS, as there are few other data management options that can cope with relational or hierarchical or object oriented data. I use a number of different RDBMS (ranging from MS SQL to PostgreSQL and MySQL). I also use Excel on occasion, and plain text editors (like Emacs), to create CSV files. Which I use depends on the details of the particular problem I am facing. While I have not yet explored them, I did notice that R includes a number of facilities for editing data (and the list of options is all the longer when I use help.search("edit"). It may be a bit quicker for you to study up on basic use of something like PostgreSQL, combined with pl/r (something I wish MySQL had), than it would be to diligently examine all the different options open to you using R. (I have a couple books I could recommend that would likely be sufficient for you to figure out what you need to do with either PostgreSQL or MySQL in a matter of a week or two). HTH Ted stephen sefick wrote: > > I am wondering if there is a better alternative than Excel for data > storage that does not require database knowledge (I will eventually > have to learn this, but it is not on my immediate todo list). I need > something that is not limited to 256 columns... I don't need any of > the built in functions in excel just a spreadsheet like program with > cells that hold data in a data.frame format for a staging area before > I get it into R. Any help would be greatly appreciated. This is not > a direct r question, but all of you folks have more experience than I > do and I am having a time finding what I need with google. > thanks in advance > > -- > Stephen Sefick > Research Scientist > Southeastern Natural Sciences Academy > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > > -K. Mullis > > __ > 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://www.nabble.com/Staging-area-for-data-before-read-into-R-tp20075962p20078353.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] About Torus Rndamiztion
Surendra champanerkar gmail.com> writes: > > Hallo > I am going through the paper on Torus randomization by Kyle E. Harms > torus randomization is an alternative to Chi-sq test of Independence When > the assumption of independence within the groups is violated > > i want to know that Is there any library regarding torus randomization > Someone said me that its in Utility.r but i could not find out this > > please help me in this regard > I know the work you're referring to, but I don't know whether Harms wrote the original code in R (quite possibly) or whether someone has translated it (also quite possible). "Someone told me there was a function in Utility.r" (freely translating from your post) isn't enough information for us to go on ... why don't you go back to whoever told you and ask for more information? Or write to the author and ask him? Here are a couple of the results of RSiteSearch("torus") that are likely to be relevant to your question (especially the second). http://finzi.psych.upenn.edu/R/library/hdeco/html/shift.html http://finzi.psych.upenn.edu/R/library/spatstat/html/rshift.ppp.html You might also try further queries on the r-sig-eco list or the r-sig-spatial list, since this is a fairly specialized question ... good luck Ben Bolker __ 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] pass longer arguments to adj of text()
Thomas Steiner wrote: NB: library(fortunes); fortune("WTFM") applies. This one I didn't get. They help to do it without a loop? No. > library(fortunes); fortune("WTFM") This is all documented in TFM. Those who WTFM don't want to have to WTFM again on the mailing list. RTFM. -- Barry Rowlingson R-help (October 2003) (TFM == The Friggin' Manual (or thereabouts), W==Write, R==Read) -- 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] ? extended rep()
Hi Folks, I'm wondering if there's a compact way to achieve the following. The "dream" is that, by analogy with rep(c(0,1),times=c(3,4)) # [1] 0 0 0 1 1 1 1 one could write rep(c(0,1),times=c(3,4,5,6)) which would produce # [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 in effect "recycling" x through 'times'. The objective is to produce a vector of alternating runs of 0s and 1s, with the lengths of the runs supplied as a vector. Indeed, more generally, something like rep(c(0,1,2), times=c(1,2,3,2,3,4)) # [1] 0 1 1 2 2 2 0 0 1 1 1 2 2 2 2 Suggestions appreciated! With thanks, Ted. E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 20-Oct-08 Time: 21:57:15 -- XFMail -- __ 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] ? extended rep()
will this do what you want: > f.rep <- function(x, times){ + # make sure the 'x' is long enough + x <- head(rep(x, length(times)), length(times)) + rep(x, times) + } > > f.rep(c(0,1), c(3,4,5,6,7)) [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 > On Mon, Oct 20, 2008 at 4:57 PM, Ted Harding <[EMAIL PROTECTED]> wrote: > Hi Folks, > I'm wondering if there's a compact way to achieve the > following. The "dream" is that, by analogy with > > rep(c(0,1),times=c(3,4)) > # [1] 0 0 0 1 1 1 1 > > one could write > > rep(c(0,1),times=c(3,4,5,6)) > > which would produce > > # [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 > > in effect "recycling" x through 'times'. > > The objective is to produce a vector of alternating runs of > 0s and 1s, with the lengths of the runs supplied as a vector. > Indeed, more generally, something like > > rep(c(0,1,2), times=c(1,2,3,2,3,4)) > # [1] 0 1 1 2 2 2 0 0 1 1 1 2 2 2 2 > > Suggestions appreciated! With thanks, > Ted. > > > E-Mail: (Ted Harding) <[EMAIL PROTECTED]> > Fax-to-email: +44 (0)870 094 0861 > Date: 20-Oct-08 Time: 21:57:15 > -- XFMail -- > > __ > 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. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ 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] ? extended rep()
Try this: with(data.frame(x = 0:1, times = 3:6), rep(x, times)) or even shorter: do.call(rep, data.frame(x = 0:1, times = 3:6)) On Mon, Oct 20, 2008 at 4:57 PM, Ted Harding <[EMAIL PROTECTED]> wrote: > Hi Folks, > I'm wondering if there's a compact way to achieve the > following. The "dream" is that, by analogy with > > rep(c(0,1),times=c(3,4)) > # [1] 0 0 0 1 1 1 1 > > one could write > > rep(c(0,1),times=c(3,4,5,6)) > > which would produce > > # [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 > > in effect "recycling" x through 'times'. > > The objective is to produce a vector of alternating runs of > 0s and 1s, with the lengths of the runs supplied as a vector. > Indeed, more generally, something like > > rep(c(0,1,2), times=c(1,2,3,2,3,4)) > # [1] 0 1 1 2 2 2 0 0 1 1 1 2 2 2 2 > > Suggestions appreciated! With thanks, > Ted. > > > E-Mail: (Ted Harding) <[EMAIL PROTECTED]> > Fax-to-email: +44 (0)870 094 0861 > Date: 20-Oct-08 Time: 21:57:15 > -- XFMail -- > > __ > 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] ? extended rep()
On 20 Oct 2008, at 22:57, (Ted Harding) wrote: I'm wondering if there's a compact way to achieve the following. The "dream" is that one could write rep(c(0,1),times=c(3,4,5,6)) which would produce # [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 in effect "recycling" x through 'times'. rep2 <- function (x, times) rep(rep(x, length.out=length(times)), times) rep2(c(0,1),times=c(3,4,5,6)) [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 Any prizes for shortest solution? ;-) Best, Stefan __ 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] ? extended rep()
Here is one other solution: x <- 0:1 times <- 3:6 rep(x + 0*times, times) This solution also works if the length of times is not a whole number of lengths of x but in that case it does give a warning which seems reasonable since that is the way recycling in R works elsewhere too. On Mon, Oct 20, 2008 at 5:17 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > Try this: > > with(data.frame(x = 0:1, times = 3:6), rep(x, times)) > > or even shorter: > > do.call(rep, data.frame(x = 0:1, times = 3:6)) > > > On Mon, Oct 20, 2008 at 4:57 PM, Ted Harding > <[EMAIL PROTECTED]> wrote: >> Hi Folks, >> I'm wondering if there's a compact way to achieve the >> following. The "dream" is that, by analogy with >> >> rep(c(0,1),times=c(3,4)) >> # [1] 0 0 0 1 1 1 1 >> >> one could write >> >> rep(c(0,1),times=c(3,4,5,6)) >> >> which would produce >> >> # [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 >> >> in effect "recycling" x through 'times'. >> >> The objective is to produce a vector of alternating runs of >> 0s and 1s, with the lengths of the runs supplied as a vector. >> Indeed, more generally, something like >> >> rep(c(0,1,2), times=c(1,2,3,2,3,4)) >> # [1] 0 1 1 2 2 2 0 0 1 1 1 2 2 2 2 >> >> Suggestions appreciated! With thanks, >> Ted. >> >> >> E-Mail: (Ted Harding) <[EMAIL PROTECTED]> >> Fax-to-email: +44 (0)870 094 0861 >> Date: 20-Oct-08 Time: 21:57:15 >> -- XFMail -- >> >> __ >> 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] Staging area for data before read into R
Why not just write your data to a CSV (comma-spaced-variable) or a tab-spaced variable text file? You didn't say what software and/or hardware was generating your data, but most gizmos these days let you dump data to CSV. No need for Excel at all. I forget :-( how many rows/columns OpenOffice.org or KOffice can handle. Carl __ 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] ? extended rep()
On 20-Oct-08 21:19:21, Stefan Evert wrote: > On 20 Oct 2008, at 22:57, (Ted Harding) wrote: >> I'm wondering if there's a compact way to achieve the >> following. The "dream" is that one could write >> >> rep(c(0,1),times=c(3,4,5,6)) >> >> which would produce >> >> # [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 >> >> in effect "recycling" x through 'times'. > > rep2 <- function (x, times) rep(rep(x, length.out=length(times)), > times) > > rep2(c(0,1),times=c(3,4,5,6)) > [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 > > Any prizes for shortest solution? ;-) > > Best, > Stefan If ever we are both within reach of 'en øl', then yes. But Gabor came up with a shorter one. I tried to shorten Gabor's but failed. However, all competitors are entitled to a consolation prize! (And that includes me ... ) Ted. E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 20-Oct-08 Time: 22:59:16 -- XFMail -- __ 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] ? extended rep()
On 20-Oct-08 21:17:22, Gabor Grothendieck wrote: > Try this: > with(data.frame(x = 0:1, times = 3:6), rep(x, times)) > > or even shorter: > do.call(rep, data.frame(x = 0:1, times = 3:6)) That is sneaky! data.frame(x = 0:1, times = 3:6) # x times # 1 0 3 # 2 1 4 # 3 0 5 # 4 1 6 (Which is why it won't work with list(x=0:1,times=3:6)) Ted. > On Mon, Oct 20, 2008 at 4:57 PM, Ted Harding > <[EMAIL PROTECTED]> wrote: >> Hi Folks, >> I'm wondering if there's a compact way to achieve the >> following. The "dream" is that, by analogy with >> >> rep(c(0,1),times=c(3,4)) >> # [1] 0 0 0 1 1 1 1 >> >> one could write >> >> rep(c(0,1),times=c(3,4,5,6)) >> >> which would produce >> >> # [1] 0 0 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 >> >> in effect "recycling" x through 'times'. >> >> The objective is to produce a vector of alternating runs of >> 0s and 1s, with the lengths of the runs supplied as a vector. >> Indeed, more generally, something like >> >> rep(c(0,1,2), times=c(1,2,3,2,3,4)) >> # [1] 0 1 1 2 2 2 0 0 1 1 1 2 2 2 2 >> >> Suggestions appreciated! With thanks, >> Ted. >> >> >> E-Mail: (Ted Harding) <[EMAIL PROTECTED]> >> Fax-to-email: +44 (0)870 094 0861 >> Date: 20-Oct-08 Time: 21:57:15 >> -- XFMail -- >> >> __ >> 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. E-Mail: (Ted Harding) <[EMAIL PROTECTED]> Fax-to-email: +44 (0)870 094 0861 Date: 20-Oct-08 Time: 23:02:00 -- XFMail -- __ 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] Categorical Response Query
Hi all, I have a queston about Categorical response. i have a data frame containing age, sex, class, success(1=success, 0=non sucess). age, sex,class are the explantory variables, and sucess is the response variable. and i can get n (the nunber of times each age occurs) and r (the number of sucess of that age). when I try to creat the regression relationship for these variables, I have seen many different cases, i just wonder which one fits me the best for this situation. 1st case, xxx.glm<-glm(success~age*sex*class,family=binomial, data=xxx.data) 2nd case xxx.glm<-glm(r/n~age*sex*class,family=binomial, data=xxx.data) 3rd case xxx.glm<-glm(cbind(r,n-r)~age*sex*class,family=binomial, data=xxx.data) what is difference between the above 3 cases? which one is the best to use? if Ii don't group the data, can I use the 1st case. if i group the data, can i use 2nd or 3rd case? please advise. Cheers. Andyer __ 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] aggregating along bins and bin-quantiles
Dear all, I would like to aggregate a data frame (consisting of 2 columns - one for the bins, say factors, and one for the values) along bins and quantiles within the bins. I have tried aggregate(data.frame$values, list(bin = data.frame $bin,Quantile=cut2(data.frame$bin,g=10)),sum) but then the quantiles apply to the population as a whole and not the individual bins. Upon this realisation I have tried aggregate(data.frame$values, list(bin = data.frame $bin,Quantile=tapply(data.frame$values,data.frame$bin,cut2,g=10)),sum) which gives the following error: Error in sort.list(unique.default(x), na.last = TRUE) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list? clearly I am doing something wrong, but cannot figure out what. I believe the error stems either from a. the output of tapply being a list of a dimension equal to the number of bins, and not a list of equal dimension as the values, or b. that somehow aggregate does not like that the second list (of the quantiles within the bins are not sorted nicely) 1. Do you have a reference for doing the summation on both bins and quantiles within the bins? 2. If not, can you give me some guidance as to what I am doing wrong and how I can solve the sort/list issue? Any help would be greatly appreciated Kind regards, Ivan Alves [[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] R Newbie Question
tIs a bit neater to create list objects for each of star1 and star2 and then, since the various functions are not used outside of gravitation stick them right in gravitation. Also we can use distance for len as well by giving it a default second arg of 0 and sqr does not seem to do much so we can eliminate that too. Making the vec computation a function eliminates some redundant code and using outer eliminates the two loops. star1 <- list(mass = 30, center = c(-0.5, 0)) star2 <- list(mass = 1, center = c(0.5, 0)) gravitation2 <- function(v1, v2) { distance <- function(a, b = 0) sqrt(sum((a-b)^2)) norm <- function(x) x/distance(x) vec <- function(x) with(x, mass * norm(center - v) / distance(v, center)^2) v <- c(v1, v2) distance(vec(star1) + vec(star2)) } xvals2 <- yvals2 <- seq(vmin, vmax, step) b2 <- outer(xvals, yvals, Vectorize(gravitation2)) On Mon, Oct 20, 2008 at 1:41 PM, Johannes Bauer <[EMAIL PROTECTED]> wrote: > Hello list, > > I just started R today and tried something quite simple. I wanted to > create a colored plot and eventually after hours of fiddling around got > it working. However, my solution seems very suboptimal and I'd really > appreciate your hints on how to improve. I believe that R already offers > many functions I coded (e.g. distance between two vectors, vector > length, vector normalization and so on). I generally didn't even figure > out how to create a simple vector or how to extract a row from a matrix > so the result is a vector (to get scalars, I use the "sum" functions, > which is an incredibly ugly workaround). > > To sum the problem up: one has a binary star system with a large star > (e.g. red giant) and a small star (e.g. white dwarf). Gravitation > between them is directly proportional to the mass and indirectly > proportional to the square of the distance. If correctly plotted, one > should be able to see the inner lagrange point L1 which is the point > where the gravitational potentials of the stars "cancel out", e.g. an > object would not be attracted to any star. Well, enough background > information, here's my rookie code - please feel free to comment on > anything :-) > > Kind regards, > Johannes > > > > star1center = vector("numeric", 2) > star1center[1] = -0.5 > star1center[2] = 0 > star1mass = 30 > > star2center = vector("numeric", 2) > star2center[1] = 0.5 > star2center[2] = 0 > star2mass = 1 > > sqr = function(x) { >return(x * x) > } > > distance = function(a, b) { >return(sqrt(sqr(a[1] - b[1]) + sqr(a[2] - b[2]))) > } > > len = function(x) { >return(sqrt(sqr(x[1]) + sqr(x[2]))) > } > > norm = function(x) { >return(x / len(x)) > } > > gravitation = function(invecx, invecy) { >invec = vector("numeric", 2) >invec[1] = invecx >invec[2] = invecy >vec1 = star1mass * norm(star1center - invec) / sqr(distance(invec, > star1center)) >vec2 = star2mass * norm(star2center - invec) / sqr(distance(invec, > star2center)) >return(len(vec1 + vec2)) > } > > vmin = -1 > vmax = 1 > step = 0.1 > vals = ((vmax - vmin) / step) + 1 > > xvals = seq(vmin, vmax, step) > yvals = seq(vmin, vmax, step) > > a = expand.grid(seq(vmin, vmax, step), seq(vmin, vmax, step)) > b = matrix(seq(1, vals*vals), vals) > > for (x in 1:vals) { >for (y in 1:vals) { >b[x, y] = gravitation(sum(a[x,][1]), sum(a[y,][1])) >} > } > filled.contour(xvals, yvals, z = b, color = heat.colors, ylim = c(-1, > 1), xlim = c(-1, 1), zlim = c(0, 100), nlevels = 100) > > __ > 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] aggregating along bins and bin-quantiles
Apologies, just a typo in the first instruction (when translating the names), the question is still valid On 21 Oct 2008, at 00:38, Ivan Alves wrote: Dear all, I would like to aggregate a data frame (consisting of 2 columns - one for the bins, say factors, and one for the values) along bins and quantiles within the bins. I have tried aggregate(data.frame$values, list(bin = data.frame $bin,Quantile=cut2(data.frame$values,g=10)),sum) but then the quantiles apply to the population as a whole and not the individual bins. Upon this realisation I have tried aggregate(data.frame$values, list(bin = data.frame $bin,Quantile=tapply(data.frame$values,data.frame$bin,cut2,g=10)),sum) which gives the following error: Error in sort.list(unique.default(x), na.last = TRUE) : 'x' must be atomic for 'sort.list' Have you called 'sort' on a list? clearly I am doing something wrong, but cannot figure out what. I believe the error stems either from a. the output of tapply being a list of a dimension equal to the number of bins, and not a list of equal dimension as the values, or b. that somehow aggregate does not like that the second list (of the quantiles within the bins which do not appear to be sorted nicely) 1. Do you have a reference for doing the summation on both bins and quantiles within the bins? 2. If not, can you give me some guidance as to what I am doing wrong and how I can solve the sort/list issue? Any help would be greatly appreciated Kind regards, Ivan Alves [[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] Mclust problem with mclust1Dplot: Error in to - from : non-numeric argument to binary operator
Dear list members, I am using Mclust in order to deconvolute a distribution that I believe is a sum of two gaussians. First I can make a model: > my.data.model = Mclust(my.data, modelNames=c("E"), warn=T, G=1:3) But then, when I try to plot the result, I get the following error: > mclust1Dplot(my.data.model, parameters = my.data.model$parameters, what = > "density") Error in to - from : non-numeric argument to binary operator Also, I'd like to allow for each gaussian to have a different variance (modelNmaes=c("V")) , but then I get another error message: > my.data.model = Mclust(my.data, modelNames=c("V"), warn=T, G=1:3) Warning messages: 1: In meV(data = data, z = z, prior = prior, control = control, warn = warn) : sigma-squared falls below threshold 2: In meV(data = data, z = z, prior = prior, control = control, warn = warn) : sigma-squared falls below threshold 3: In summary.mclustBIC(Bic, data, G = G, modelNames = modelNames) : best model occurs at the min or max # of components considered 4: In Mclust(my.data, modelNames = c("V"), warn = T, G = 1:3) : optimal number of clusters occurs at min choice Many thanks in advance for your help, Best wishes, Emmanuel If you would like to reproduce the above, the dataset is: my.data=c( 0.,0.0052,0.,-0.2136,0.4625,0.6047,0.,0.7370,0.5059 ,-0.8060,-1.0790,0.,-1.5397,-0.0720,-3.2180,-1.6980,0.,2.2845 ,-1.0741,0.,0.1020,-0.6010,0.2210,-0.0120,1.0785,0.,-0.4536 ,-0.1127,-0.2032,-0.0421,-1.6818,-0.9935,-2.2105,-0.7963,-0.1820,-2.0468 ,0.6161,-1.7663,-0.6800,-2.1290,-0.0167,0.,0.,0.,0.5427 ,-0.0170,0.,0.,-0.6576,0.9055,0.1409,-0.1409,0.,0.3730 ,-0.1800,-1.3141,0.6786,-0.2480,-2.5110,-0.1340,0.3000,-1.7350,0. ,-0.5464,0.,-0.7513,-1.9056,-1.4823,-0.5376,-0.4516,-1.1391,0. ,-2.2560,1.3770,0.3390,-2.6023,-1.0880,-0.1444,0.,-0.1459,0.1740 ,0.,0.3310,0.0749,1.0360,-0.8345,-0.6843,-3.5171,-1.9482,-0.4972 ,-0.0130,-2.0290,-0.2812,0.,0.,-0.0164,0.,-1.9220,-1.5941 ,-1.0840,0.,0.0459,-2.2121,-1.1485,-1.1485,0.,-0.4449,-0.5001 ,0.3520,1.9980,-3.8385,1.7160,1.0020,-0.2250,-0.8265,-0.2032) __ 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] Staging area for data before read into R
Hi Stephen, You don't say what "staging" is - do you mean for data entry or loading a data file for review, or ... ? In general, I keep away from Excel for data transfer purposes. It tends to make "intelligent" decisions on data types leading to strange & bizarre results (unless you explicitly type each column - which most users don't do). Integers are interpreted as dates, high order zeros are stripped off of ZIP codes, and the like. HTH, Jim Porzak TGN.com San Francisco, CA http://www.linkedin.com/in/jimporzak useR Group SF: http://ia.meetup.com/67/ On Mon, Oct 20, 2008 at 11:27 AM, stephen sefick <[EMAIL PROTECTED]> wrote: > I am wondering if there is a better alternative than Excel for data > storage that does not require database knowledge (I will eventually > have to learn this, but it is not on my immediate todo list). I need > something that is not limited to 256 columns... I don't need any of > the built in functions in excel just a spreadsheet like program with > cells that hold data in a data.frame format for a staging area before > I get it into R. Any help would be greatly appreciated. This is not > a direct r question, but all of you folks have more experience than I > do and I am having a time finding what I need with google. > thanks in advance > > -- > Stephen Sefick > Research Scientist > Southeastern Natural Sciences Academy > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > >-K. Mullis > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Staging area for data before read into R
There is a list of free spreadsheets with their row and column limits at this link: http://en.wikipedia.org/wiki/OpenOffice.org_Calc On Mon, Oct 20, 2008 at 3:13 PM, stephen sefick <[EMAIL PROTECTED]> wrote: > sorry excel 2003 with no immediate update in the future. > > On Mon, Oct 20, 2008 at 3:12 PM, Gabor Grothendieck > <[EMAIL PROTECTED]> wrote: >> You didn't say which version of Excel you are using but Excel 2007 >> allows 16,384 columns. >> >> On Mon, Oct 20, 2008 at 2:27 PM, stephen sefick <[EMAIL PROTECTED]> wrote: >>> I am wondering if there is a better alternative than Excel for data >>> storage that does not require database knowledge (I will eventually >>> have to learn this, but it is not on my immediate todo list). I need >>> something that is not limited to 256 columns... I don't need any of >>> the built in functions in excel just a spreadsheet like program with >>> cells that hold data in a data.frame format for a staging area before >>> I get it into R. Any help would be greatly appreciated. This is not >>> a direct r question, but all of you folks have more experience than I >>> do and I am having a time finding what I need with google. >>> thanks in advance >>> >>> -- >>> Stephen Sefick >>> Research Scientist >>> Southeastern Natural Sciences Academy >>> >>> Let's not spend our time and resources thinking about things that are >>> so little or so large that all they really do for us is puff us up and >>> make us feel like gods. We are mammals, and have not exhausted the >>> annoying little problems of being mammals. >>> >>>-K. Mullis >>> >>> __ >>> 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. >>> >> > > > > -- > Stephen Sefick > Research Scientist > Southeastern Natural Sciences Academy > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > >-K. Mullis > __ 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] Staging area for data before read into R
Well, I am going to type in ever value because the data sheets are of counts of insects that I identified, so I should be okay with accuracy... I really just need something that allows for more than 256 columns as I have encounter over 256 species of insects in even small streams. I think calc with it's 1000ish columns will do the trick... thanks everbody for your help. On Mon, Oct 20, 2008 at 8:25 PM, Gabor Grothendieck <[EMAIL PROTECTED]> wrote: > There is a list of free spreadsheets with their row and column limits > at this link: > http://en.wikipedia.org/wiki/OpenOffice.org_Calc > > On Mon, Oct 20, 2008 at 3:13 PM, stephen sefick <[EMAIL PROTECTED]> wrote: >> sorry excel 2003 with no immediate update in the future. >> >> On Mon, Oct 20, 2008 at 3:12 PM, Gabor Grothendieck >> <[EMAIL PROTECTED]> wrote: >>> You didn't say which version of Excel you are using but Excel 2007 >>> allows 16,384 columns. >>> >>> On Mon, Oct 20, 2008 at 2:27 PM, stephen sefick <[EMAIL PROTECTED]> wrote: I am wondering if there is a better alternative than Excel for data storage that does not require database knowledge (I will eventually have to learn this, but it is not on my immediate todo list). I need something that is not limited to 256 columns... I don't need any of the built in functions in excel just a spreadsheet like program with cells that hold data in a data.frame format for a staging area before I get it into R. Any help would be greatly appreciated. This is not a direct r question, but all of you folks have more experience than I do and I am having a time finding what I need with google. thanks in advance -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ 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. >>> >> >> >> >> -- >> Stephen Sefick >> Research Scientist >> Southeastern Natural Sciences Academy >> >> Let's not spend our time and resources thinking about things that are >> so little or so large that all they really do for us is puff us up and >> make us feel like gods. We are mammals, and have not exhausted the >> annoying little problems of being mammals. >> >>-K. Mullis >> > -- Stephen Sefick Research Scientist Southeastern Natural Sciences Academy Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ 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] Variable shortlisting for the logistic regression
I nominate the below 2 paragraphs (or a possible shortening of them) as a new fortune. While not as entertaining as many of the current fortunes, the wisdom gained and sentiment expressed deserves preservation and easy reference for future posters who think that Frank is only trying to be funny. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] 801.408.8111 > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > project.org] On Behalf Of Darin Brooks > Sent: Sunday, October 19, 2008 9:11 AM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Cc: r-help@r-project.org > Subject: Re: [R] Variable shortlisting for the logistic regression > > Frank's remark was made in response to my posting. As "funny" as it > was - > it was the best thing that could have happened to me. It sparked an > enlightening discussion between my committee and me (in particular, the > pros > & cons of stepwise vs. information theoretic approach to model > selection). > Being new to the R help list, I had no idea who Frank was. I googled > him > (and asked around) and found very quickly that he should be taken > seriously. > And so should his remark. > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > project.org] On > Behalf Of Rolf Turner > Sent: Thursday, October 16, 2008 1:34 PM > To: useR > Cc: r-help@r-project.org > Subject: Re: [R] Variable shortlisting for the logistic regression > > > > On 17/10/2008, at 8:22 AM, useR wrote: > > > Let's try to bring this discussion back again after Frank made > > very funny remark! > > Frank's remark was *serious*. Take it seriously. > > cheers, > > Rolf Turner > > ## > Attention:\ This e-mail message is privileged and > confid...{{dropped:9}} > > __ > 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. > No virus found in this incoming message. > Checked by AVG - http://www.avg.com > > 8:02 PM > > __ > 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] New mailing list r-sig-hpc
As interest in topics that are often grouped under the catch-all umbrella of 'high performance computing with R' has grown over the last few months, it has been suggested to create a dedicated mailing list. Now, thanks to Martin Maechler who tirelessly looks after all R mailing matters, such a list has been set up as 'r-sig-hpc'. Suitable topics for discussion may comprise - parallel computing approaches for R with, but not limited to any of Rmpi, rpvm, snow, nws, rsprng, ... - use of batch / queue management system such as Slurm, Condor, Sun Grid - Engine, LSF, ... - profiling and debugging R, in particular for compiled - large-scale automation and scripting or any other topic you deem suitable for 'high performance computing with R'. List information, as well as subscription information, is available at https://stat.ethz.ch/mailman/listinfo/r-sig-hpc Regards, Dirk -- Three out of two people have difficulties with fractions. __ 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] Staging area for data before read into R
How about simply a text editor, typing in your data, separated by commas or tabs or spaces? One row for each case/subject/observation? R can read that in easily. A good, open-source, free data entry program is EpiData. www.epidata.dk. It is simple to use but probably more than you need for task. --Chris Christopher W. Ryan, MD SUNY Upstate Medical University Clinical Campus at Binghamton 40 Arch Street, Johnson City, NY 13790 cryanatbinghamtondotedu PGP public keys available at http://home.stny.rr.com/ryancw/ "If you want to build a ship, don't drum up the men to gather wood, divide the work and give orders. Instead, teach them to yearn for the vast and endless sea." [Antoine de St. Exupery] stephen sefick wrote: > I am wondering if there is a better alternative than Excel for data > storage that does not require database knowledge (I will eventually > have to learn this, but it is not on my immediate todo list). I need > something that is not limited to 256 columns... I don't need any of > the built in functions in excel just a spreadsheet like program with > cells that hold data in a data.frame format for a staging area before > I get it into R. Any help would be greatly appreciated. This is not > a direct r question, but all of you folks have more experience than I > do and I am having a time finding what I need with google. > thanks in advance > __ 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] Staging area for data before read into R
> Well, I am going to type in ever value because the data sheets are of > counts of insects that I identified, so I should be okay with > accuracy... I really just need something that allows for more than > 256 columns as I have encounter over 256 species of insects in even > small streams. ... Oh, ugh, that sounds difficult and prone to entry errors. You might be better off organizing in the 'long' format with 4-5 columns: siteID, subSiteID, species, count, comments You can then reshape(), or use the reshape package, or even the 'pivot table' available in excel and other spreadcheats. Glad you have an answer. Enjoy your day. cur -- Curt Seeliger, Data Ranger Raytheon Information Services - Contractor to ORD [EMAIL PROTECTED] 541/754-4638 [EMAIL PROTECTED] wrote on 10/20/2008 06:01:43 PM: > Well, I am going to type in ever value because the data sheets are of > counts of insects that I identified, so I should be okay with > accuracy... I really just need something that allows for more than > 256 columns as I have encounter over 256 species of insects in even > small streams. I think calc with it's 1000ish columns will do the > trick... thanks everbody for your help. > > On Mon, Oct 20, 2008 at 8:25 PM, Gabor Grothendieck > <[EMAIL PROTECTED]> wrote: > > There is a list of free spreadsheets with their row and column limits > > at this link: > > http://en.wikipedia.org/wiki/OpenOffice.org_Calc > > > > On Mon, Oct 20, 2008 at 3:13 PM, stephen sefick <[EMAIL PROTECTED]> wrote: > >> sorry excel 2003 with no immediate update in the future. > >> > >> On Mon, Oct 20, 2008 at 3:12 PM, Gabor Grothendieck > >> <[EMAIL PROTECTED]> wrote: > >>> You didn't say which version of Excel you are using but Excel 2007 > >>> allows 16,384 columns. > >>> > >>> On Mon, Oct 20, 2008 at 2:27 PM, stephen sefick <[EMAIL PROTECTED]> wrote: > I am wondering if there is a better alternative than Excel for data > storage that does not require database knowledge (I will eventually > have to learn this, but it is not on my immediate todo list). I need > something that is not limited to 256 columns... I don't need any of > the built in functions in excel just a spreadsheet like program with > cells that hold data in a data.frame format for a staging area before > I get it into R. Any help would be greatly appreciated. This is not > a direct r question, but all of you folks have more experience than I > do and I am having a time finding what I need with google. > thanks in advance > > -- > Stephen Sefick > Research Scientist > Southeastern Natural Sciences Academy > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > > -K. Mullis > > __ > 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. > > >>> > >> > >> > >> > >> -- > >> Stephen Sefick > >> Research Scientist > >> Southeastern Natural Sciences Academy > >> > >> Let's not spend our time and resources thinking about things that are > >> so little or so large that all they really do for us is puff us up and > >> make us feel like gods. We are mammals, and have not exhausted the > >> annoying little problems of being mammals. > >> > >>-K. Mullis > >> > > > > > > -- > Stephen Sefick > Research Scientist > Southeastern Natural Sciences Academy > > Let's not spend our time and resources thinking about things that are > so little or so large that all they really do for us is puff us up and > make us feel like gods. We are mammals, and have not exhausted the > annoying little problems of being mammals. > > -K. Mullis > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] converting a row of a data.frame to a vector"
Try: as.vect = function(x) { t1 = as.matrix(x) t2 = aperm(t1) t3 = as.vector(t2) return(t3) } This function converts entire dataframe into a vector. Alexander Pui PhD Candidate in Hydroclimatology, University of New South Wales Email: [EMAIL PROTECTED] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to plot the histogram and the curve in the same graph
i want to plot the histogram and the curve in the same graph.if i have a set of data ,i plot the histogram and also want to see what distribution it was.So i want to plot the curve to know what distribution it like. -- View this message in context: http://www.nabble.com/how-to-plot-the-histogram-and-the-curve-in--the-same-graph-tp20082506p20082506.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] Simulation of data
Hi listers, I am working on a program of statistical analysis of simulated data and I've been searching the error at the program, but I didn't find it! It is something about the WHILE procedure, the error says: Error in while (ecart >= d) { : missing value where TRUE/FALSE needed Thanks in advance! Márcio k<-100 d<-0.00112 z<-rnorm(100, 0, 1) prop<-rep(0,100) for (i in 1:100){ if (z[i]>1.75){ prop[i]<-1} else{prop[i]<-0}} proportion<-mean(prop) ecart<-sqrt((proportion*(1-proportion))/k) while(ecart>=d){ prop_<-0 w<- rnorm(1, 0, 1) z<-c(z,w) {if (w>1.75){ prop_<-1} else{ prop_<-0} } prop<-c(prop, prop_) proportion<-proportion+(prop[k+1]-proportion/(k+1)) ecart<-sqrt((proportion*(1-proportion))/(k+1)) k<-k+1 } -- View this message in context: http://www.nabble.com/Simulation-of-data-tp20082754p20082754.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] Using an image background with graphics
Greg, > The rimage package has functions for reading in and plotting > jpeg files that you could use for displaying the photograph. > If you then can find 2 points in the image (not on the same > horizontal or vertical line) for which you know the > coordinates in the coordinate system that you want to plot > in, then you can use the updateusr function from the > TeachingDemos package to set the user coordinates, then use > points/lines or other functions that can add to the current > plot (e.g. contour with add=TRUE) to overlay the information > of interest to the plot. I tried this, and your approach works great except for one thing. I would like to plot to a pdf device, and when I do so my grayscale image takes on a gridded appearance, with thick horizontal and vertical lines of lighter gray. These don't appear of course if I use jpeg() instead of pdf(). How can I get rid of those? Thanks, Scott Waichler [EMAIL PROTECTED] __ 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] Using an image background with graphics
Most likely this is a bug in your pdf viewer: try turning off anti-aliasing there (or use a better viewer, if that is not an option). It is a symptom of anti-aliasing of the rectangles used to plot image pixels. You haven't told us which 'a pdf device' and there are several for R, depending on the OS. pdf() does not do this, nor does cairo_pdf(). Some of the third-party devices did last time I looked. On Mon, 20 Oct 2008, Waichler, Scott R wrote: Greg, The rimage package has functions for reading in and plotting jpeg files that you could use for displaying the photograph. If you then can find 2 points in the image (not on the same horizontal or vertical line) for which you know the coordinates in the coordinate system that you want to plot in, then you can use the updateusr function from the TeachingDemos package to set the user coordinates, then use points/lines or other functions that can add to the current plot (e.g. contour with add=TRUE) to overlay the information of interest to the plot. I tried this, and your approach works great except for one thing. I would like to plot to a pdf device, and when I do so my grayscale image takes on a gridded appearance, with thick horizontal and vertical lines of lighter gray. These don't appear of course if I use jpeg() instead of pdf(). How can I get rid of those? Thanks, Scott Waichler [EMAIL PROTECTED] -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ 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] For loop - how to assign "i" when it is not an element of an index?
Hello, I'm trying to build a for loop, where I estimate a series of models with different sets of (time series) data. However my for loop doesn't recognize the "i" # code window.1=anomalies.CAK[(positions(anomalies.CAK)>=timeDate("1/1/1971") & positions(anomalies.CAK)<=timeDate("6/30/1991") )] window.14=anomalies.CAK[(positions(anomalies.CAK)>=timeDate("1/1/1984") & positions(anomalies.CAK)<=timeDate("6/30/2004") ),] for (i in 1:14){ ar1mods[1] = lm ( formula = window.i~ ar(1) ) } # end code ### Problem: Object "window.i" not found Anybody have a quick tip on what I'm doing wrong? -- View this message in context: http://www.nabble.com/For-loop---how-to-assign-%22i%22-when-it-is-not-an-element-of-an-index--tp20083917p20083917.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] For loop - how to assign "i" when it is not an element of an index?
Scotty Nelson hotmail.com> writes: > I'm trying to build a for loop, where I estimate a series of models with > different sets of (time series) data. > However my for loop doesn't recognize the "i" > > # code > window.1=anomalies.CAK[(positions(anomalies.CAK)>=timeDate("1/1/1971") & > positions(anomalies.CAK)<=timeDate("6/30/1991") )] > > window.14=anomalies.CAK[(positions(anomalies.CAK)>=timeDate("1/1/1984") & > positions(anomalies.CAK)<=timeDate("6/30/2004") ),] > > for (i in 1:14){ > ar1mods[1] = lm ( formula = window.i~ ar(1) ) > } The easiest would be to put the selection of the cases into the loop, and always use the same formula. You could also use formula=paste("window.",i,sep=""). That approach will work for the simple example, but you might run into eval-problems later (though probably not for lm). # B.D. Ripley val(subst) workaround #http://finzi.psych.upenn.edu/R/Rhelp02a/archive/16599.html Dieter __ 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 plot the histogram and the curve in the same graph
leo_wa hotmail.com> writes: > > i want to plot the histogram and the curve in the same graph.if i have a > set of data ,i plot the histogram and also want to see what distribution > it was.So i want to plot the curve to know what distribution it like. See the example under histogram/lattice. Also have a look at Deepayan's book-site. http://lmdvr.r-forge.r-project.org/figures/figures.html Dieter __ 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/R-PLUS/S Conference ***USAR2009*** April 26-30, 2009 - Las Vegas, USA | Call For Posters
Call For Posters: By now, there's a good chance you've heard about USAR2009 - R/R-PLUS/S Conference. R-PLUS is the next evolution of R: Interactive, Comprehensive, Highly Visual. Join us in Las Vegas, USA for the USAR2009 held at Ceasar's Palace on April 26-29, 2009. More information can be found at: www.Experience-Rplus.com/Call_Posters.asp Poster presentations provide an excellent opportunity for R/RPLUS/S users to present their projects in a one-to-one setting and receive professional feedback from leaders in their field. The USAR2009 Poster session is open to all R/RPLUS/S users – from corporate or academic fields. Submit your posters to [EMAIL PROTECTED] USAR2009 April 26-30, 2009 Las Vegas, USA [EMAIL PROTECTED] __ 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.