[R] recursive question
Hi all, How can store the recursive results from each step without using global operator -? Thanks ahead. Xiaohui Chen Dept. of Statistics UBC, Canada _ Dont waste time standing in linetry shopping online. Visit Sympatico / MSN __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Data frames questions
1) Is there a way to build an empty data frame, containing nothing but the data frame variable names? Yes, you can do it one way as followings: df1-as.data.frame(matrix(nrow=2,ncol=2),row.names=c(R1,R2)) 2) Is there a way to reorder the variables in a data frame, e.g. When I go to write out a data frame using write.table or write.matrix, I want the output in a certain order... df2-as.data.frame(matrix(1:4,nrow=2,ncol=2),row.names=c(R3,R4)) df2-df2[c(2,1),] 3) How to I append to the bottom of a dataframe? df2-rbind(df2,c(5,6)) Xiaohui Chen Dept. of Statistics UBC, Canada From: Jonathan Greenberg [EMAIL PROTECTED] To: R-help r-help@stat.math.ethz.ch Subject: [R] Data frames questions Date: Sat, 23 Sep 2006 14:54:00 -0700 Hi there, couple of questions on data frames: 1) Is there a way to build an empty data frame, containing nothing but the data frame variable names? 2) Is there a way to reorder the variables in a data frame, e.g. When I go to write out a data frame using write.table or write.matrix, I want the output in a certain order... 3) How to I append to the bottom of a dataframe? Thanks! --j -- Jonathan A. Greenberg, PhD NRC Research Associate NASA Ames Research Center MS 242-4 Moffett Field, CA 94035-1000 Office: 650-604-5896 Cell: 415-794-5043 AIM: jgrn307 MSN: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting grouped data object
I don't get your meaning in what is in datagrp, anyway, try: X11() par(new=T) before calling: plot(data.grp, outer = ~ y) Xiaohui Chen Dept. of Statistics UBC, Canada From: Afshartous, David [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Subject: [R] plotting grouped data object Date: Sat, 23 Sep 2006 18:09:38 -0400 All, I'd like to plot the main relationship of a grouped data object for all levels of a factor in a single panel. The sample code below creates a separate panel for each level of the factor. I realize that this could be done in other ways, but I'd like to do it via plotting the grouped data object. thanks! dave z = rnorm(18, mean=0, sd=1) x = rep(1:6, 3) y = factor(rep(c(I, C, P), each = 6)) dat = data.frame(x, y, z) data.grp = groupedData(z ~ x | y, data = dat) plot(data.grp, outer = ~ y) ### this produces 1 line each in 3 panels ### how to collapse all 3 lines into 1 panel? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Question about merge()
merge() can handle this if you specify the by parameters to the same length vector for x and y. The parameters corresponds the columns you want to filter out under certain conditions and add the values to the merging data.frame. For example(modified from No.1 example from ?merge): authors - data.frame( surname = c(Tukey, Venables, Tierney, Ripley, McNeil), nationality = c(US, Australia, US, UK, Australia), deceased = c(yes, rep(no, 4)),year=c(2000,2001,2000,2001,2000)) books - data.frame( name = c(Tukey, Venables, Tierney, Ripley, Ripley, McNeil, R Core), title = c(Exploratory Data Analysis, Modern Applied Statistics ..., LISP-STAT, Spatial Statistics, Stochastic Simulation, Interactive Data Analysis, An Introduction to R), other.author = c(NA, Ripley, NA, NA, NA, NA, Venables Smith),year=c(1999,2001,2000,2001,2000,2001,2002)) #Compare the following results: merge(authors,books,by.x=surname,by.y=name) merge(authors,books,by.x=c(surname,year),by.y=c(name,year)) Hope this can be some help of you. Xiaohui Chen Dept. of Statistics UBC, Canada From: Jonathan Greenberg [EMAIL PROTECTED] To: R-help r-help@stat.math.ethz.ch Subject: [R] Question about merge() Date: Sat, 23 Sep 2006 15:08:22 -0700 If I want to do a join based on *two* matching fields in two data frames, can merge() handle this? It appears to only handle a single matching column -- do I need to make a metacolumn or is there some way to do this? E.g.: Dataframe 1 contains columns A,B,C and Dataframe 2 contains A,B,D I want an output A,B,C,D which places C and D together if A and B match (otherwise, make two new rows, e.g. Ax,Bx,Cx,nodata and Ay,By,nodata,Dy) --j -- Jonathan A. Greenberg, PhD NRC Research Associate NASA Ames Research Center MS 242-4 Moffett Field, CA 94035-1000 Office: 650-604-5896 Cell: 415-794-5043 AIM: jgrn307 MSN: [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Buy what you want when you want it on Sympatico / MSN Shopping __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 store recursive results
Hi Patrick, Thanks for your suggestion. I find your method works for the functions with integer paramters. For example, If we have function f: f-function(i) { if(i1) i*f(i-1) else 1 } and then using: ans - vector(list, n) for(i in 1:5) { ans[[i]] - f(i) } the ans should be: [[1]] [1] 1 [[2]] [1] 2 [[3]] [1] 6 [[4]] [1] 24 [[5]] [1] 120 But actually, we there is no such a i can be referrenced in f(), no parametric function for example, this will be a problem. Anyway, thanks a lot for your suggestions. Cheers, Xiaohui Chen Dept. of Statistics UBC, Canada From: Patrick Burns [EMAIL PROTECTED] To: X.H Chen [EMAIL PROTECTED] Subject: Re: [R] how to store recursive results Date: Fri, 22 Sep 2006 10:26:35 +0100 It isn't clear to me exactly what you are asking, but I think that a list might be what you are after. Something like: ans - vector(list, n) for(i in 1:n) { ans[[i]] - } X.H Chen wrote: Hi all, How to store recursive resutls from a function for each step without using global operators -? Thanks ahead. Xiaohui Chen Dept. of Statistics UBC, Canada _ Dont waste time standing in linetry shopping online. Visit Sympatico / MSN __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 store recursive results
Hi Gabor, Thanks for pointing out this for me. However, what I try to get is how to construct such form a function f that ret-f(...), where ret contains the each recursive result from f, and meantime f consists of no - operator. Do you have any idea how to implemet this. Thanks a lot for your suggestions. Cheer Xiaohui Chen Dept. of Statistics UBC, Canada From: Gabor Grothendieck [EMAIL PROTECTED] To: X.H Chen [EMAIL PROTECTED] CC: r-help@stat.math.ethz.ch Subject: Re: [R] how to store recursive results Date: Fri, 22 Sep 2006 06:49:22 -0400 Note that - is not necessarily global: if (exists(x)) rm(x) f - function() { x - 2 g - function() x - 3 g() x } f() # 3 exists(x) # FALSE On 9/22/06, X.H Chen [EMAIL PROTECTED] wrote: Hi all, How to store recursive resutls from a function for each step without using global operators -? Thanks ahead. Xiaohui Chen Dept. of Statistics UBC, Canada _ Don't waste time standing in linetry shopping online. Visit Sympatico / MSN __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Buy what you want when you want it on Sympatico / MSN Shopping __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 store recursive results
Hi Bálint, Thanks very much for your suggestions. The party package is a little bit complicated to use. Do you have a much simpler example for this problem? Anyway, I am gonna try this package. Cheers, Xiaohui Chen Dept. of Statistics UBC, Canada From: Bálint Czúcz [EMAIL PROTECTED] To: X.H Chen [EMAIL PROTECTED] CC: r-help@stat.math.ethz.ch Subject: Re: [R] how to store recursive results Date: Fri, 22 Sep 2006 12:21:02 +0200 One suggestion: as a recursive list. For example have a look at the 'party' package and the BinaryTree class. I hope this helps. Bálint On 22/09/06, X.H Chen [EMAIL PROTECTED] wrote: Hi all, How to store recursive resutls from a function for each step without using global operators -? Thanks ahead. Xiaohui Chen Dept. of Statistics UBC, Canada _ Don't waste time standing in linetry shopping online. Visit Sympatico / MSN __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] install error uder Cygwin
Dear R users, I have a question about R installation under Cygwin. When running ./configure, I can't pass the checking phase due to an error: --with-readline=yes (default) and headers/libs are not available... Anybody who can tell me why this error arises? Thanks a lot. Xiaohui Chen Dept. of Statistics UBC, Canada _ Buy what you want when you want it on Sympatico / MSN Shopping __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 store recursive results
Hi all, How to store recursive resutls from a function for each step without using global operators -? Thanks ahead. Xiaohui Chen Dept. of Statistics UBC, Canada _ Dont waste time standing in linetry shopping online. Visit Sympatico / MSN __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.