Re: [R] Saving iterative components
Thanks a lot Uwe Ligges, I've abandoned R for a few time but now I'm working with it, so I've a question about the last problem that you solved: instead to write cv_1994- idw.cv(X01_1994) cv_1995- idw.cv(X01_1995) cv_1996- idw.cv(X01_1996) cv_1997- idw.cv(X01_1997) . cv_2006- idw.cv(X01_2006) cv_2007- idw.cv(X01_2007) cv_2008- idw.cv(X01_2008) can I use a more compact expression Thanks -- View this message in context: http://r.789695.n4.nabble.com/Saving-iterative-components-tp2553676p3086697.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] Saving iterative components
On Tue, Dec 14, 2010 at 10:34 AM, Annalaura annalaura.ru...@imaa.cnr.it wrote: Thanks a lot Uwe Ligges, I've abandoned R for a few time but now I'm working with it, so I've a question about the last problem that you solved: instead to write cv_1994- idw.cv(X01_1994) cv_1995- idw.cv(X01_1995) cv_1996- idw.cv(X01_1996) cv_1997- idw.cv(X01_1997) . cv_2006- idw.cv(X01_2006) cv_2007- idw.cv(X01_2007) cv_2008- idw.cv(X01_2008) can I use a more compact expression Yes. There are nicer ways to formulate the problem (and the solution), but without access to the object all I can is a shot in the dark. ##obtain a vector of variable names vars - names(Tmese[, -(1:2)]) ##apply the function 'idw.cv' iteratively, each time ##using a 'vars' element as the functions first argument; ##store the results in a list res - lapply(vars, idw.cv) res Regards Liviu PS For more on loops and the apply family check [1]. [1] http://promberger.info/files/rnews-vectorvsloops2008.pdf Thanks -- View this message in context: http://r.789695.n4.nabble.com/Saving-iterative-components-tp2553676p3086697.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. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Saving iterative components
Hi, I'm trying to understand when and how to use do.call(). In this case, would it work with do.call() instead of lapply(), like this? vars - list(names(Tmese[, -(1:2)])) res - do.call(idw.cv, vars) Thanks, Ivan Le 12/14/2010 11:48, Liviu Andronic a écrit : On Tue, Dec 14, 2010 at 10:34 AM, Annalauraannalaura.ru...@imaa.cnr.it wrote: Thanks a lot Uwe Ligges, I've abandoned R for a few time but now I'm working with it, so I've a question about the last problem that you solved: instead to write cv_1994- idw.cv(X01_1994) cv_1995- idw.cv(X01_1995) cv_1996- idw.cv(X01_1996) cv_1997- idw.cv(X01_1997) . cv_2006- idw.cv(X01_2006) cv_2007- idw.cv(X01_2007) cv_2008- idw.cv(X01_2008) can I use a more compact expression Yes. There are nicer ways to formulate the problem (and the solution), but without access to the object all I can is a shot in the dark. ##obtain a vector of variable names vars- names(Tmese[, -(1:2)]) ##apply the function 'idw.cv' iteratively, each time ##using a 'vars' element as the functions first argument; ##store the results in a list res- lapply(vars, idw.cv) res Regards Liviu PS For more on loops and the apply family check [1]. [1] http://promberger.info/files/rnews-vectorvsloops2008.pdf Thanks -- View this message in context: http://r.789695.n4.nabble.com/Saving-iterative-components-tp2553676p3086697.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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Saving iterative components
On 24.09.2010 17:51, Annalaura wrote: Hi, I need help! I am trying to iterate an iterative process to do cross vadation and store the results each time. I have a Spatial data.frame, called Tmese str(Tmese) Formal class 'SpatialPointsDataFrame' [package sp] with 5 slots ..@ data :'data.frame': 14 obs. of 17 variables: .. ..$ ID : int [1:14] 73 68 49 62 51 79 69 77 57 53 ... .. ..$ Stazione: Factor w/ 29 levels ALIANO,BONIFATI,..: 2 3 4 5 10 11 12 16 17 19 ... .. ..$ X01_1994: num [1:14] 9.34 10.67 5.29 11.86 9.15 ... .. ..$ X01_1995: num [1:14] 7.07 9.22 2.32 9.3 6.66 ... .. ..$ X01_1996: num [1:14] 9.41 10.4 5.99 12.3 9.93 ... .. ..$ X01_1997: num [1:14] 10.67 10.65 5.76 12.82 10.1 ... .. ..$ X01_1998: num [1:14] 9.57 10.12 4.44 10.34 8.97 ... .. ..$ X01_1999: num [1:14] 8.96 10.21 3.23 10.83 7.74 ... .. ..$ X01_2000: num [1:14] 6.58 8.46 2.8 8.37 6.55 ... Now I want to do 14 cross validation and I wrote a function idw.cv- function(x){ tmp- krige.cv(x~1, Tmese, model=NULL) return(tmp) } But when I run it, it doesn't work, it says: cv_1994- idw.cv(X01_1994) Actually this means that you want to pass an object called X01_1994 to the function rather than a symbol for the formula. What you could do in order to stay with the formula notation is to write your own generic / methods that handles different kinds of input including formulae and handle them. Otherwise a quick and dirty approach (with some shortcomings) for example is: idw.cv- function(x){ form - as.formula(paste(x, ~1)) tmp- krige.cv(form, Tmese, model=NULL) return(tmp) } cv_1994- idw.cv(X01_1994) Uwe Ligges Error in eval(expr, envir, enclos) : object 'X01_1994' not found WhyPlease Help me! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Saving iterative components
Hi, I need help! I am trying to iterate an iterative process to do cross vadation and store the results each time. I have a Spatial data.frame, called Tmese str(Tmese) Formal class 'SpatialPointsDataFrame' [package sp] with 5 slots ..@ data :'data.frame': 14 obs. of 17 variables: .. ..$ ID : int [1:14] 73 68 49 62 51 79 69 77 57 53 ... .. ..$ Stazione: Factor w/ 29 levels ALIANO,BONIFATI,..: 2 3 4 5 10 11 12 16 17 19 ... .. ..$ X01_1994: num [1:14] 9.34 10.67 5.29 11.86 9.15 ... .. ..$ X01_1995: num [1:14] 7.07 9.22 2.32 9.3 6.66 ... .. ..$ X01_1996: num [1:14] 9.41 10.4 5.99 12.3 9.93 ... .. ..$ X01_1997: num [1:14] 10.67 10.65 5.76 12.82 10.1 ... .. ..$ X01_1998: num [1:14] 9.57 10.12 4.44 10.34 8.97 ... .. ..$ X01_1999: num [1:14] 8.96 10.21 3.23 10.83 7.74 ... .. ..$ X01_2000: num [1:14] 6.58 8.46 2.8 8.37 6.55 ... Now I want to do 14 cross validation and I wrote a function idw.cv- function(x){ tmp- krige.cv(x~1, Tmese, model=NULL) return(tmp) } But when I run it, it doesn't work, it says: cv_1994- idw.cv(X01_1994) Error in eval(expr, envir, enclos) : object 'X01_1994' not found WhyPlease Help me! -- View this message in context: http://r.789695.n4.nabble.com/Saving-iterative-components-tp2553676p2553676.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] Saving Iterative Components
Dear All, I am trying to iterate an iterative process (i know R is not the best place for so much looping but i have to so tough!) and store the resulting data from each iteration to then be graphed. In simple form the script looks like this for(i in tracks) { a - (subset(data, data$Id==i)) result.dataset - function(a, other.arguements) ### this function is the other iterative process, but its in another script and is imported in so dont worry about it. } I want the result.dataset to be unique for each iteration, something like result.dataset.i. makes sense to me but not to R! Im teaching myself here and apparently im a rubbish teacher so any help would be much appreciated! Thanks in advance, Phil -- View this message in context: http://www.nabble.com/Saving-Iterative-Components-tp24974133p24974133.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] Saving Iterative Components
try something like this using 'list' results.dataset - list() for(i in tracks) { a - (subset(data, data$Id==i)) result.dataset[[i]] - function(a, other.arguements) ### this function is the other iterative process, but its in another script and is imported in so dont worry about it. } You will have a list with the values from each iteration that you can access On Fri, Aug 14, 2009 at 12:00 PM, Phil Tphiliprhodritay...@googlemail.com wrote: Dear All, I am trying to iterate an iterative process (i know R is not the best place for so much looping but i have to so tough!) and store the resulting data from each iteration to then be graphed. In simple form the script looks like this for(i in tracks) { a - (subset(data, data$Id==i)) result.dataset - function(a, other.arguements) ### this function is the other iterative process, but its in another script and is imported in so dont worry about it. } I want the result.dataset to be unique for each iteration, something like result.dataset.i. makes sense to me but not to R! Im teaching myself here and apparently im a rubbish teacher so any help would be much appreciated! Thanks in advance, Phil -- View this message in context: http://www.nabble.com/Saving-Iterative-Components-tp24974133p24974133.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.