Re: [R] aggregate factor
Try this. as.numeric(levels(fishdata$Age))[fishdata$Age] HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Bill Szkotnicki Verzonden: vrijdag 7 september 2007 21:10 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] aggregate factor Hi, I am using aggregate to compute means for later plotting. There are two factors involved and the problem is that the values of the second factor ( Age ) in the means are not in the right order because 10 comes inbetween 1 and 2 What I really want is the numeric value of Age but as.numeric and as.integer returns the level value instead. Is there a way to easily get the numeric value? I am using Windows R 2.5.1 Thanks, str(fishdata) 'data.frame': 372 obs. of 6 variables: $ Lake: Factor w/ 3 levels EVANS,JOLLIET,..: 3 3 3 3 3 3 3 3 3 3 ... $ Age : int 1 1 1 1 1 1 1 1 1 1 ... $ TL : int 132 120 125 115 130 120 115 110 117 116 ... $ W : int 10 10 10 10 10 10 10 10 10 20 ... $ Sex : Factor w/ 3 levels F,I,M: 1 1 2 2 2 1 1 1 2 2 ... $ WT : num 0.23 0.23 0.23 0.23 0.23 0.23 0.23 0.23 0.23 0.23 ... fishdatameans=aggregate(fishdata$TL, list(Lake = fishdata$Lake, Age=fishdata$Age), mean) # Now Age is a Factor but 10 is in the wrong position. fishdatameans$Age [1] 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 6 6 6 7 8 9 10 Levels: 0 1 10 2 3 4 5 6 7 8 9 as.numeric(fishdatameans$Age) [1] 1 2 2 2 4 4 4 5 5 5 6 6 6 7 7 8 8 8 9 10 11 3 # What I want is 0 1 1 1 2 2 2 3 3 3 4 4 4 5 5 6 6 6 7 8 9 10 Bill __ 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] Legend issue with ggplot2
Dear useRs, I'm struggling with the new version of ggplot2. In the previous version I did something like this. But now this yield an error (object fill not found). library(ggplot2) dummy - data.frame(x = rep(1:10, 4), group = gl(4, 10)) dummy$y - dummy$x * rnorm(4)[dummy$group] + 5 * rnorm(4)[dummy$group] dummy$min - dummy$y - 5 dummy$max - dummy$y + 5 ggplot(data = dummy, aes(x = x, max = max, min = min, fill = group)) + geom_ribbon() + geom_line(aes(y = max, colour = fill)) + geom_line(aes(y = min, colour = fill)) When I adjust the code to the line below, it works again. But this time with two legend keys for group. Any idea how to display only one legend key for group? The ggplot-code aboved yielded only on legend key. ggplot(data = dummy, aes(x = x, max = max, min = min, colour = group, fill = group)) + geom_ribbon() + geom_line(aes(y = max)) + geom_line(aes(y = min)) Thanks, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney __ 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] Legend issue with ggplot2
Thanks Hadley, I've been struggling with this all afternoon. But now it's working again. Since I'm using it in a script, the few extra lines don't bother me that much. Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: hadley wickham [mailto:[EMAIL PROTECTED] Verzonden: maandag 3 september 2007 15:15 Aan: ONKELINX, Thierry CC: r-help@stat.math.ethz.ch Onderwerp: Re: [R] Legend issue with ggplot2 On 9/3/07, ONKELINX, Thierry [EMAIL PROTECTED] wrote: Dear useRs, I'm struggling with the new version of ggplot2. In the previous version I did something like this. But now this yield an error (object fill not found). library(ggplot2) dummy - data.frame(x = rep(1:10, 4), group = gl(4, 10)) dummy$y - dummy$x * rnorm(4)[dummy$group] + 5 * rnorm(4)[dummy$group] dummy$min - dummy$y - 5 dummy$max - dummy$y + 5 ggplot(data = dummy, aes(x = x, max = max, min = min, fill = group)) + geom_ribbon() + geom_line(aes(y = max, colour = fill)) + geom_line(aes(y = min, colour = fill)) Strange - I'm not sure why that ever worked. When I adjust the code to the line below, it works again. But this time with two legend keys for group. Any idea how to display only one legend key for group? The ggplot-code aboved yielded only on legend key. ggplot(data = dummy, aes(x = x, max = max, min = min, colour = group, fill = group)) + geom_ribbon() + geom_line(aes(y = max)) + geom_line(aes(y = min)) You can manually turn off one of the legends: sc - scale_colour_discrete() sc$legend - FALSE .last_plot + sc It's not very convenient though, so I'll think about how to do this automatically. The legends need to be more intelligent about only displaying the minimum necessary. Hadley __ 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 signal the end of the table?
Have you tried read.table() and the similar functions? I think they would provide a much more simple solution for your problem. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Yuchen Luo Verzonden: woensdag 29 augustus 2007 19:41 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] How to signal the end of the table? I am using a for loop to read a table row by row and I have to specify how many records are there in the table. I need to read row by row because the table is huge and the memory not large enough for the whole table.: number.of.records=100 fp=file(abc.csv,r) pos=seek(fp, rw=read) for (i in 1:number.of.record){ current.row=scan(file=fp, sep=',', what=list(count=1, cusip6=, idate=1, spread=1.1, vol252=1.1, vol1000=1.1, st_debt=1.1, lt_debt=1.1 , total_liab= 1.1, cr=1.1, shrout=1.1, prc=1.1, mkt_cap=1.1, rtng=1.1, sec=1.1, cr3m=1.1, cr5y=1.1, ust3m=1.1, ust5y=1.1), flush=TRUE, nlines=1,quiet=T) ... } I need to know the number of records in the table and put it in the variable named number.of.records. When I have a new table that I do not know how many records it has, I use excel to open the file to figure it out and put it in variable number.of.records. I often have many tables to try and every one of them has thousands of recordsit takes a lot of time and trouble to adjust the code every time I read a different table. I am wondering if I can change the for loop to a while loop: while (the end of the table has not been reached) { current.row=scan(file=fp, sep=',', what=list(count=1, cusip6=, idate=1, spread=1.1, vol252=1.1, vol1000=1.1, st_debt=1.1, lt_debt=1.1 , total_liab= 1.1, cr=1.1, shrout=1.1, prc=1.1, mkt_cap=1.1, rtng=1.1, sec=1.1, cr3m=1.1, cr5y=1.1, ust3m=1.1, ust5y=1.1), flush=TRUE, nlines=1,quiet=T) ... } The problem is how to articulate while (the end of the table has not been reached), or equivalently, how to signal the end of the table? Best Wishes Yuchen Luo [[alternative HTML version deleted]] __ 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] sql query over local tables
Jorge, I'm assuming that you mean dataframes of matrices. Then you could use merge to join both dataframes into a new one. See ?merge for more detail. HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Jorge Cornejo Donoso Verzonden: dinsdag 28 augustus 2007 22:05 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] sql query over local tables Hi i have to table with IDs in each one. I want to make a join (as in sql) by the ID. Is any way to use the RODBC package (or other) in local tables (not a access, mysql, sql, etc. ) and made the join? Thanks in advance __ 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] several plots on several pages - bug in par(mfg())?
Dear Rainer, Your could try something like this. test - try( plot(runif(ff)) ) if(class(test) == try-error){ #put here code for an empty plot } Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Rainer M. Krug Verzonden: vrijdag 17 augustus 2007 9:49 Aan: Greg Snow CC: r-help; [EMAIL PROTECTED] Onderwerp: Re: [R] several plots on several pages - bug in par(mfg())? Greg Snow wrote: Oops, I read further down in your original post and see that you already knew about par(mfg=c(2,1)). To get it to advance to page 2 for the 4th plot try calling plot.new() which should move you to the next page, then doing par(mfg=c(1,1)) should cause the next graph to be at the top. Hope this helps, Thanks - I found plot.new() and it is working. But: If the first plot command fails, par(mfg=c(2,1)) does NOT move to the second one - if you try the code below, you will see. Is this a bug or am I doing something wrong? ## Set layout to three rows and only oine column par( mfcol=c(3,1), oma=c(0,0,0,0), mar=c(4, 4, 2, 2) ) ## First row par(mfg=c(1,1)) try( plot(runif(ff)) ) ## plot fails due to something. ## Second row par(mfg=c(2,1)) try( plot(runif(100)) ) ##actually is plotted in first row ## Third row par(mfg=c(3,1)) plot(runif(1000)) ## plotted in third row -- NEW EMAIL ADDRESS AND ADDRESS: [EMAIL PROTECTED] [EMAIL PROTECTED] WILL BE DISCONTINUED END OF MARCH Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Plant Conservation Unit Department of Botany University of Cape Town Rondebosch 7701 South Africa Tel: +27 - (0)21 650 5776 (w) Fax: +27 - (0)86 516 2782 Fax: +27 - (0)21 650 2440 (w) Cell: +27 - (0)83 9479 042 Skype:RMkrug email:[EMAIL PROTECTED] [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] several plots on several pages
Dear Rainer, Have you considered using Sweave? HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Rainer M. Krug Verzonden: donderdag 16 augustus 2007 14:58 Aan: r-help Onderwerp: [R] several plots on several pages Hi version _ platform i686-pc-linux-gnu arch i686 os linux-gnu system i686, linux-gnu status major 2 minor 5.1 year 2007 month 06 day27 svn rev42083 language R version.string R version 2.5.1 (2007-06-27) I want to create a pdf withe three graphs on a page and with two pages: - | 1 | - | 2 | - | 3 | - NEW PAGE - | 4 | - | 5 | - | 6 | - Graph 1 should ALWAYS be at that spot, graph two also, even if graph one produces an error when plotting (the area can be empty, but doesn't have to.) I produced the foolowing code below, but I have a few problems: 1) how can I create a new page in the pdf? 2) how can I make sure that the second graph is in position 2 when graph one produces an error when plotting I(as in the example)? Everything works OK (for the firsat page) when graph one is plotted. I have the feeling, that I am thinking to complicated. Any help welcome, Rainer pdf(test.pdf) try( { ## Set layout to three rows and only oine column par( mfcol=c(3,1), oma=c(0,0,0,0), mar=c(4, 4, 2, 2) ) ## First row par(mfg=c(1,1)) try( plot(runif(ff)) ) ## Second row par(mfg=c(2,1)) try( plot(runif(100)) ) ## Third row par(mfg=c(3,1)) plot(runif(1000)) ## THE NEXT THREE SHOULD BE ON A NEW PAGE IN THE PDF ## Set layout to three rows and only oine column par( mfcol=c(3,1), oma=c(0,0,0,0), mar=c(4, 4, 2, 2) ) ## First row par(mfg=c(1,1)) try( plot(runif(ff)) ) ## Second row par(mfg=c(2,1)) try( plot(runif(100)) ) ## Third row par(mfg=c(3,1)) plot(runif(1000)) } ) dev.off() -- NEW EMAIL ADDRESS AND ADDRESS: [EMAIL PROTECTED] [EMAIL PROTECTED] WILL BE DISCONTINUED END OF MARCH Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Plant Conservation Unit Department of Botany University of Cape Town Rondebosch 7701 South Africa Tel: +27 - (0)21 650 5776 (w) Fax: +27 - (0)86 516 2782 Fax: +27 - (0)21 650 2440 (w) Cell: +27 - (0)83 9479 042 Skype:RMkrug email:[EMAIL PROTECTED] [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] Linear Regression with slope equals 0
Dear Ed, In my opinion you don't need to set the slope to zero. Just test if the slope in lm(d ~ t) is significant. If it is significant then you have evidence that the slope is NOT zero. But when it is not significant (and in your example it is), you can't say that it is zero. But doing some power calculations allows you to estimate the smallest detectable slope. The estimated slope in your example is 0.49. Your design has a power of 13% to detect slopes of this size. The real slope has to be about 1.75 in order to have 80% power. Let's say that it would matter if the slope is about 2 or larger and it won't matter is it is below 2. The power to detect a slope of 2 is 89%, hence you would likely get a significant slope if it was larger then 2. Since the slope was not significant, it's safe to say that the slope is not larger then 2. But if a slope of 0.5 would matter, you couldn't make this kind of assumptions because the power to detect a slope of 0.5 is only 13%. So the change of rejecting the null hypothesis (slope = 0) when slope = 0.5 is too small. HTH, Thierry power.trend - function(repetitions = 5, x = c(0, 1), sd = 1, slope = 1, alpha = 0.05){ + X - rep(x, repetitions) + ncp - slope ^ 2 * sum((X - mean(X))^2) / sd ^ 2 + return(1 - pf(qf(1 - alpha, 1, length(X) - 2), 1, length(X) - 2, ncp = ncp)) + } df - data.frame(t = 1:6, d = c(303, 302, 304, 306, 307, 303)) fit - lm(d ~ t, data = df) summary(fit) Call: lm(formula = d ~ t, data = df) Residuals: 123456 0.04762 -1.43810 0.07619 1.59048 2.10476 -2.38095 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 302.4667 1.7849 169.45 7.28e-09 *** t 0.4857 0.45831.060.349 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 1.917 on 4 degrees of freedom Multiple R-Squared: 0.2192, Adjusted R-squared: 0.02402 F-statistic: 1.123 on 1 and 4 DF, p-value: 0.349 power.trend(repetitions = 1, x = df$t, sd = sd(df$d), slope = coef(fit)[t]) [1] 0.1292668 power.trend(repetitions = 1, x = df$t, sd = sd(df$d), slope = 1.75) [1] 0.8021454 ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens [EMAIL PROTECTED] Verzonden: dinsdag 14 augustus 2007 13:37 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Linear Regression with slope equals 0 Hi there, am trying to run a linear regression with a slope of 0. I have a dataset as follows t d 1 303 2 302 3 304 4 306 5 307 6 303 I would like to test the significance that these points would lie on a horizontal straight line. The standard regression lm(d~t) doesn't seem to allow the slope to be set. Any help very welcome. ed __ 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] Find out the workspace name
?getwd() ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Luis Ridao Cruz Verzonden: woensdag 8 augustus 2007 11:39 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Find out the workspace name R-help, Sometimes there might be several R sessions open at the same time. In Windows no name appears in the R main bar (just R Console) Is it possible to know the name of the workspace. I ussually write it on the script I am working on but I wish to know without having to search in a text file. Thanks in advance __ 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] ggplot2 qplot and add
I think you need something like. qplot(appetitive.stimulus, graphLabels, data=related.differences, size=variance, colour=Appetitive Stimulus, xlim=c(-20,20), main=Title here, xlab=Differences, ylab=Header Concepts) + geom_point(aes(colour = Aversive Stimulus)) HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Emilio Gagliardi Verzonden: donderdag 2 augustus 2007 19:11 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] ggplot2 qplot and add Hi there, I have some simple frequencies I want to plot into one graph. I had it working, and now I can't figure out whats going wrong. All the data is stored in a dataframe, and i finally managed to order the factor correctly! Each column is a variable and contains integers for the same set of values in the column that contains the headers for each row (graphLabels). So, I get the data and my first call is: app - qplot(appetitive.stimulus, graphLabels, data=related.differences, size=variance, colour=Appetitive Stimulus, xlim=c(-20,20), main=Title here, xlab=Differences, ylab=Header Concepts) which works great. Now, there are 16 columns in my dataframe that I want to output together, so i tried the following: ave - qplot(aversive.stimulus, graphLabels, data=related.differences, size=variance, colour=Aversive Stimulus, xlim=c(-20,20), main=Title here, xlab=Differences, ylab=Header Concepts, add=app) which according to what i can find (and actually got working at some point) should add the data from the two columns to the same graph. However, that is not what is happening now. The 'add' parameter does add the first plot object, but instead of both sets of data appearing, only 'app' appears in the output. If I remove the 'add' command, 'ave' outputs correctly. What am i doing wrong here? It feels like I'm missing something ridiculously apparent. Thanks for your help! emilio [[alternative HTML version deleted]] __ 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 a smooth curve from predict
What you need is b - data.frame(x = 1:10, y = c(10,9,8,7,6,6.5,7,8,9,10)) w - gls(y ~ I(x)+I(x^2),correlation=corARMA(p=1),method=ML,data=b) Newdata - data.frame(x = seq(1, 10, length = 41)) plot(predict(w, newdata = Newdata), type=l) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Wilson, Andrew Verzonden: dinsdag 31 juli 2007 12:22 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Plotting a smooth curve from predict Probably a very simple query: When I try to plot a curve from a fitted polynomial, it comes out rather jagged, not smooth like fitted curves in other stats software. Is there a way of getting a smooth curve in R? What I'm doing at the moment (for the sake of example) is: x - c(1,2,3,4,5,6,7,8,9,10) y - c(10,9,8,7,6,6.5,7,8,9,10) b - data.frame(cbind(x,y)) w - gls(y ~ I(x)+I(x^2),correlation=corARMA(p=1),method=ML,data=b) plot(predict(w),type=l) Many thanks, Andrew Wilson __ 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] Tabs in PDF documents
I think you need to escape the '\' character in your string by adding an extra '\' in front of it. So try pdf(junk.pdf) par(family=mono) plot(1,1) text(1,1, \\txx) mtext(\\txx) dev.off() HTH, Thierry -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] namens Dennis Fisher Verzonden: ma 30-7-2007 14:25 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Tabs in PDF documents Colleagues, I am using R 2.5.1 on an Intel Mac (OS 10) to create PDF outputs using pdf(); same problem exists in Linux (RedHat 9) While adding text to the document with text() and mtext(), I encounter the following problem: In order to align the text, I have embedded tabs (\t) in some of the text. Each time I do so, I get the following error messages: Warning: font metrics unknown for character 0x9 Warning: font width unknown for character 0x9 and the tabs are ignored. I have tied par() with and without family=mono. Is there a work-around available for this? Dennis COMMANDS: pdf(junk.pdf) par(family=mono) plot(1,1) text(1,1, \txx) mtext(\txx) dev.off() __ 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] Strange warning in summary.lm
Dear Peter, Uwe and Brian, I've found some more problems with options(OutDec = ,). 1) as.numeric yields NA where it shouldn't z - c(12, 12,34, 12.34) options(OutDec = ,) as.numeric(z) [1] 12,00NA 12,34 Warning message: NAs introduced by coercion in: as.double.default(z) # should result in c(12, 12.34, NA) options(OutDec = .) as.numeric(z) [1] 12.00NA 12.34 Warning message: NAs introduced by coercion in: as.double.default(z) 2) anova yields the same warning as summary x - runif(100) y - rnorm(100) options(OutDec = ,) summary(lm(y~x)) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -2,81744 -0,61680 0,02107 0,66309 2,20599 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0,073531 0,195880 -0,3750,708 x0,007519 0,318159 0,0240,981 Residual standard error: 0,9795 on 98 degrees of freedom Multiple R-Squared: 5.699e-06, Adjusted R-squared: -0.0102 F-statistic: 0.0005585 on 1 and 98 DF, p-value: 0,9812 Warning message: NAs introduced by coercion in: as.double.default(Cf[okP]) anova(lm(y~x)) Analysis of Variance Table Response: y Df Sum Sq Mean Sq F value Pr(F) x 1 0,001 0,001 6e-04 0,9812 Residuals 98 94,031 0,960 Warning message: NAs introduced by coercion in: as.double.default(Cf[okP]) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens ONKELINX, Thierry Verzonden: donderdag 19 juli 2007 13:56 Aan: Peter Dalgaard CC: r-help@stat.math.ethz.ch; Uwe Ligges Onderwerp: Re: [R] Strange warning in summary.lm Dear Peter, Here's an example. Notice the warning in the last two lines of the summary with options(OutDec = ,). It's not present with options(OutDec = .). Cheers, Thierry x - runif(100) y - rnorm(100) options(OutDec = ,) summary(lm(y~x)) Call: lm(formula = y ~ x) Residuals: Min1QMedian3Q Max -2,389749 -0,607002 0,006969 0,689535 1,713197 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 0,033970,17774 0,1910,849 x -0,092190,29518 -0,3120,755 Residual standard error: 0,868 on 98 degrees of freedom Multiple R-Squared: 0.0009943, Adjusted R-squared: -0.0092 F-statistic: 0.09754 on 1 and 98 DF, p-value: 0,7555 Warning message: NAs introduced by coercion in: as.double.default(Cf[okP]) options(OutDec = .) summary(lm(y~x)) Call: lm(formula = y ~ x) Residuals: Min1QMedian3Q Max -2.389749 -0.607002 0.006969 0.689535 1.713197 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 0.033970.17774 0.1910.849 x -0.092190.29518 -0.3120.755 Residual standard error: 0.868 on 98 degrees of freedom Multiple R-Squared: 0.0009943, Adjusted R-squared: -0.0092 F-statistic: 0.09754 on 1 and 98 DF, p-value: 0.7555 -- -- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: Peter Dalgaard [mailto:[EMAIL PROTECTED] Verzonden: donderdag 19 juli 2007 13:37 Aan: ONKELINX, Thierry CC: Uwe Ligges; r-help@stat.math.ethz.ch Onderwerp: Re: [R] Strange warning in summary.lm ONKELINX, Thierry wrote: The problem also exists in a clean workspace. But I've found the troublemaker. I had set options(OutDec = ,). Resetting this to options(OutDec = .) solved the problem. Thanks, Thierry Oups. That sounds like there's a bug somewhere. Can you cook up a minimal example which shows the behaviour? -- O__ Peter Dalgaard Øster Farimagsgade 5
[R] Ggplot2 equivalent of axis and problem with log scale
Dear useRs, Recently I've discorved ggplot2 and I must say that I really like it, although the documentation still is a working in progress. My first question: How can I change the position of the labels and the text of the labels? With a basic plot I would use axis(2, at = position.of.the.ticks, labels = text.at.the.ticks). Could someone provide me with an example of how to do this with ggplot2? The second question is probably a little bug. If I plot the y-axis in log10 scale then geom_errorbar still plot the values in the original scale. See the example below. The second plot is what I would suspect when plotting the first graph. library(ggplot2) df - data.frame(x = rep(1:10, 10), y = rnorm(100)) df$y - 10 ^ (df$x + df$y) df - cbind(df, predict(lm(I(log10(y)) ~ x, data = df), interval = c)) df[, 3:5] - 10 ^ df[, 3:5] ggplot(data = df, aes(x = x, y = y)) + geom_point() + scale_y_log10() + geom_line(aes(y = fit)) + geom_errorbar(aes(min = lwr, max = upr)) ggplot(data = df, aes(x = x, y = y)) + geom_point() + scale_y_log10() + geom_line(aes(y = fit)) + geom_errorbar(aes(min = log10(lwr), max = log10(upr))) Thanks, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney __ 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] Strange warning in summary.lm
-Oorspronkelijk bericht- Van: Prof Brian Ripley [mailto:[EMAIL PROTECTED] Verzonden: woensdag 25 juli 2007 12:20 Aan: ONKELINX, Thierry CC: r-help@stat.math.ethz.ch Onderwerp: Re: [R] Strange warning in summary.lm On Wed, 25 Jul 2007, ONKELINX, Thierry wrote: Dear Peter, Uwe and Brian, I've found some more problems with options(OutDec = ,). 1) as.numeric yields NA where it shouldn't It should: where does it say otherwise? OutDec affects output, only. I was doing something like options(OutDec = ,) df - data.frame(var = rep(1:8/4, 10), x = rnorm(80)) df.a - aggregate(df$x, by = list(var = df$var), FUN = sum) as.numeric(df.a$var) [1] NA NA NA 1 NA NA NA 2 Warning message: NAs introduced by coercion in: as.double.default(df.a$var) because I needed df.a$var as numeric again. 2) anova yields the same warning as summary It does not in current R: try any fairly recent version of R-devel. Please don't keep reporting a problem we have already fixed, as the FAQ and the posting guide explicitly ask of you. Sorry about that. I wasn't aware that the error was in a fixed subroutine that is used by summary and anova. I'm hestating to use a R-devel version because I haven't tried installing R from a tar.gz (I'm one of those lazy windows users that prefer the .exe version). For now I think I'll return to the good old option(OutDec = .). [...] -- 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@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] values from a linear model
It's not very clear to me but I think summary(mod)$coef[, Std. Error] is wat you need? Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Manuele Pesenti Verzonden: dinsdag 24 juli 2007 12:03 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] values from a linear model Dear R users, how can I extrapolate values listed in the summary of an lm model but not directly available between object values such as the the standard errors of the calculated parameters? for example I got a model: mod - lm(Crd ~ 1 + Week, data=data) and its summary: summary(mod) Call: lm(formula = Crd ~ 1 + Week, data = data, model = TRUE, y = TRUE) Residuals: Min 1Q Median 3QMax -4.299e-03 -1.653e-03 2.628e-05 1.291e-03 5.130e-03 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 1.000e+01 3.962e-04 25238.73 2e-16 *** Week5.038e-04 6.812e-0673.96 2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.001966 on 98 degrees of freedom Multiple R-Squared: 0.9824, Adjusted R-squared: 0.9822 F-statistic: 5469 on 1 and 98 DF, p-value: 2.2e-16 I'm interested in values of Std. Error of coefficients... thank you very much Best regards Manuele -- Manuele Pesenti [EMAIL PROTECTED] [EMAIL PROTECTED] http://mpesenti.polito.it __ 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] Strange warning in summary.lm
The problem also exists in a clean workspace. But I've found the troublemaker. I had set options(OutDec = ,). Resetting this to options(OutDec = .) solved the problem. Thanks, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: Uwe Ligges [mailto:[EMAIL PROTECTED] Verzonden: donderdag 19 juli 2007 10:39 Aan: ONKELINX, Thierry CC: r-help@stat.math.ethz.ch Onderwerp: Re: [R] Strange warning in summary.lm ONKELINX, Thierry wrote: Dear useRs, Lately I noticed a strange warning in the summary of a lm-object. Any idea what this warning is about? I'm using R 2.5.1 on Win XP pro. x - rnorm(100) y - rnorm(100) summary(lm(y~x)) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -1,77809 -0,68438 -0,04409 0,63891 2,30863 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0,002170,09244 -0,0230,981 x0,013150,09628 0,1370,892 Residual standard error: 0,9236 on 98 degrees of freedom Multiple R-Squared: 0.0001903, Adjusted R-squared: -0.01001 F-statistic: 0.01866 on 1 and 98 DF, p-value: 0,8916 Warning message: NAs introduced by coercion in: as.double.default(Cf[okP]) Probably you have an object in your workspace or another attached environment in the search path that conflicts with objects that are required to call summary(lm(...)). E.g. some lm... oder summary... function? Best, Uwe Ligges Thanks, Thierry -- -- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney __ 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] Strange warning in summary.lm
Dear Peter, Here's an example. Notice the warning in the last two lines of the summary with options(OutDec = ,). It's not present with options(OutDec = .). Cheers, Thierry x - runif(100) y - rnorm(100) options(OutDec = ,) summary(lm(y~x)) Call: lm(formula = y ~ x) Residuals: Min1QMedian3Q Max -2,389749 -0,607002 0,006969 0,689535 1,713197 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 0,033970,17774 0,1910,849 x -0,092190,29518 -0,3120,755 Residual standard error: 0,868 on 98 degrees of freedom Multiple R-Squared: 0.0009943, Adjusted R-squared: -0.0092 F-statistic: 0.09754 on 1 and 98 DF, p-value: 0,7555 Warning message: NAs introduced by coercion in: as.double.default(Cf[okP]) options(OutDec = .) summary(lm(y~x)) Call: lm(formula = y ~ x) Residuals: Min1QMedian3Q Max -2.389749 -0.607002 0.006969 0.689535 1.713197 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) 0.033970.17774 0.1910.849 x -0.092190.29518 -0.3120.755 Residual standard error: 0.868 on 98 degrees of freedom Multiple R-Squared: 0.0009943, Adjusted R-squared: -0.0092 F-statistic: 0.09754 on 1 and 98 DF, p-value: 0.7555 ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: Peter Dalgaard [mailto:[EMAIL PROTECTED] Verzonden: donderdag 19 juli 2007 13:37 Aan: ONKELINX, Thierry CC: Uwe Ligges; r-help@stat.math.ethz.ch Onderwerp: Re: [R] Strange warning in summary.lm ONKELINX, Thierry wrote: The problem also exists in a clean workspace. But I've found the troublemaker. I had set options(OutDec = ,). Resetting this to options(OutDec = .) solved the problem. Thanks, Thierry Oups. That sounds like there's a bug somewhere. Can you cook up a minimal example which shows the behaviour? -- 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@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] Strange warning in summary.lm
Dear useRs, Lately I noticed a strange warning in the summary of a lm-object. Any idea what this warning is about? I'm using R 2.5.1 on Win XP pro. x - rnorm(100) y - rnorm(100) summary(lm(y~x)) Call: lm(formula = y ~ x) Residuals: Min 1Q Median 3Q Max -1,77809 -0,68438 -0,04409 0,63891 2,30863 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0,002170,09244 -0,0230,981 x0,013150,09628 0,1370,892 Residual standard error: 0,9236 on 98 degrees of freedom Multiple R-Squared: 0.0001903, Adjusted R-squared: -0.01001 F-statistic: 0.01866 on 1 and 98 DF, p-value: 0,8916 Warning message: NAs introduced by coercion in: as.double.default(Cf[okP]) Thanks, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney __ 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] Problem with Sweave and pdf version 1.4
Dear useRs, I'm trying to use ggplot2 in Sweave (R 2.5.1). The plots use the alpha channel, so I need to use pdf version 1.4. Search the mailinglist archive I found two solutions: \SweaveOpts{echo = FALSE, pdf.version=1.4} and explicit writing to a pdf 1.4 file. The latter works but the first doesn't. Probably I'm doing something wrong (see the Rnw file below). The file tmp_tmp.pdf is generated but is corrupt. Using the second option, is there a way to create the filename based on some variable. Something like x - sometext filename - paste(x, .pdf, sep = ) pdf(file=filename, version=1.4) But how can I pass the filename to \includegraphics? The Rnw file \documentclass[11pt]{report} \usepackage{Sweave} \SweaveOpts{echo = FALSE, pdf.version=1.4, eps = FALSE} \begin{document} \begin{figure} \centering tmp, fig = T, width = 5, height = 4= library(ggplot2) x - runif(100) dataset - data.frame(x = x, y = 5 * x + rnorm(100)) ggplot(dataset, aes(y = y, x = x)) + stat_smooth() + geom_jitter() @ \caption{Here comes a caption.} \label{fig:tmp} \end{figure} \begin{figure} \centering fig = F= pdf(file=foo.pdf, version=1.4) ggplot(dataset, aes(y = y, x = x)) + stat_smooth() + geom_jitter() dev.off() @ \incudegraphics{foo} \caption{Here comes a caption.} \label{fig:foo} \end{figure} \end{document} Thanks in advance, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney __ 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] Speeding up
Dear Bjorn, Do you know that mean(xy*ind)+mean(xy*!ind) yields the same value for all i? Maybe you meant mean(xy[ind]) + mean(xy[!ind]) sapply(xord, function(xordi, xy = x){ ind - xy xordi mean(xy*ind)+mean(xy*!ind) }) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Van Campenhout Bjorn Verzonden: maandag 9 juli 2007 15:12 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Speeding up Hi R-helpers, I am new in programming and R, so this may be basic. I need to speed up a procedure where I minimize some function on different partitions of the data. I can do this with a loop, as for instance in: i-1 meanmin-Inf while (ilength(x)) { ind-xxord[i] if (some function to be minimizedmeanmin) { meanmin-some function to be minimized indmin-xord[i] } i-i+1 } print(indmin) I learned that I should avoid loops, so I found the following alternative: dmat-outer(x,xord,)*1 ss-apply(dmat,2,function (z) some function to be minimized) indmin-xord[which.min(ss)] print(indmin) But this does not lead to spectacular improvements (obviously, this is dependent on the function and the length of x, and this dmat does not seem to be an elegant solution to me). Is there scope for substantial improvement? Any pointers will be greatly appreciated. Below an example with some timings. set.seed(12345) x - rnorm(1000, mean = 5, sd = 2) xord-x[order(x)] system.time({i-1 + meanmin-Inf + while (ilength(x)) { + ind-xxord[i] + if ((mean(x*ind)+mean(x*!ind))meanmin) { + meanmin-mean(x*ind)+mean(x*!ind) + indmin-xord[i] + } + i-i+1 + } + print(indmin)}) [1] 3.826595 user system elapsed 0.140.000.14 system.time({dmat-outer(x,xord,)*1 + ss-apply(dmat,2,function (z) mean(x*z)+mean(x*!z)) + indmin-xord[which.min(ss)] + print(indmin)}) [1] 3.826595 user system elapsed 0.420.060.49 __ 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] Loop and cbind
A more elegant way to do this is standard - sapply(calm, function(calmi){calmi / sqrt(emaTA(calmi ^ 2, 0.03))}) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens john seers (IFR) Verzonden: woensdag 4 juli 2007 15:19 Aan: livia; r-help@stat.math.ethz.ch Onderwerp: Re: [R] Loop and cbind Hi In what way does it not work? My guess is that you have not declared your values outside the for loop. As they are local they will be lost on exit. You need to declare them before: ewma-vector(length=12) standard-vector(length=12) for ... { } John Seers --- Hi, I would like to apply the following function for i between 1 and 12, and then construct a list of the return series. for (i in 1:12){ ewma[i] - emaTA(calm[[i]]^2,0.03) standard[i]- calm[[i]]/sqrt(ewma[i]) standard - cbind(standard[i]) } But it does not work. Could anyone give me some advice how can I achieve this? Many thanks -- View this message in context: http://www.nabble.com/Loop-and-cbind-tf4024291.html#a11430500 Sent from the R help mailing list archive at Nabble.com. __ 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-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] A More efficient method?
Cat - c('a','a','a','b','b','b','a','a','b') C1 - ifelse(Cat == 'a', -1, 1) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Keith Alan Chamberlain Verzonden: woensdag 4 juli 2007 15:45 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] A More efficient method? Dear Rhelpers, Is there a faster way than below to set a vector based on values from another vector? I'd like to call a pre-existing function for this, but one which can also handle an arbitrarily large number of categories. Any ideas? Cat=c('a','a','a','b','b','b','a','a','b')# Categorical variable C1=vector(length=length(Cat)) # New vector for numeric values # Cycle through each column and set C1 to corresponding value of Cat. for(i in 1:length(C1)){ if(Cat[i]=='a') C1[i]=-1 else C1[i]=1 } C1 [1] -1 -1 -1 1 1 1 -1 -1 1 Cat [1] a a a b b b a a b Sincerely, KeithC. Psych Undergrad, CU Boulder (US) RE McNair Scholar __ 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] select row
Assuming that id is a character. tab[tab$id == 25-2006, ] Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Leonardo Lami Verzonden: dinsdag 3 juli 2007 11:34 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] select row Hi all, I have a little problem selecting some rows from a data.frame. I'd like to select the rows where a determinated column take a partivolar value. For example: tab id x y 124-2005 1621814 4834991 224-2005 1621856 4834907 324-2005 1621763 4834956 4 25-2006 1622330 4835189 5 25-2006 1622533 4834834 6 25-2006 1622535 4834909 7 25-2006 1622543 4834803 8 28-2005 1622798 4835043 9 28-2005 1622299 4835129 I'd like to select the row where id=25-2006 I searched on the search of the R site but I did'nt find anything of simple. Can someone help me? Thank you very much Leonardo __ 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 get the position of an element in a vector ?
?which.max ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Benoit Chemineau Verzonden: dinsdag 3 juli 2007 16:12 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] how to get the position of an element in a vector ? Hi, dear R developers, I've got a vector of monthly volatilities and i would like to get the position of the highest volatility of the vector without computing a loop. Is there a function that could give me such a result ? a-c(1,2,4,100,3) the highest value is the fourth of the vector. how can i get 4 without a loop going through the vector ? Thanks ! Benoit. [[alternative HTML version deleted]] __ 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] multiple return
Put the return values in a vector or list somma - function (a, b) { c - a+b return (c(a = a, b = b, c = c)) } somma(5,7) a b c 5 7 12 somma - function (a, b) { c - a+b return (list(a = a, b = b, c = c)) } somma(5,7) $a [1] 5 $b [1] 7 $c [1] 12 Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Manuele Pesenti Verzonden: vrijdag 22 juni 2007 12:38 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] multiple return Dear User, what's the correct way to obtain a multiple return from a function? for example creating the simple function: somma - function (a, b) { c - a+b return (a, b, c) } when I call it, it runs but returns the following output: somma(5, 7) $a [1] 5 $b [1] 7 $c [1] 12 Warning message: return multi-argomento sono deprecati in: return(a, b, c) i.e. multi-return is deprecated... thanks a lot best regards Manuele -- Manuele Pesenti [EMAIL PROTECTED] [EMAIL PROTECTED] http://mpesenti.polito.it __ 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] sorting data
Why don't you use a package like RODBC and read the data directly from the Excel file? Then you probably won't have to worry on how to get the dates in the right format. Another, maybe easier, solution is to export the Excel to CSV and then use read.csv(). Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens dala Verzonden: donderdag 21 juni 2007 15:54 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] sorting data I have a 2 columns, Date and Number, in Excel. I copy and paste them into Notepad. I can use scan() to import the file but how do I plot this data with Date as the x-axis? -- View this message in context: http://www.nabble.com/sorting-data-tf3958889.html#a11233613 Sent from the R help mailing list archive at Nabble.com. __ 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] Got Unexpected ELSE error
You need to put the else statement on the same line as the closing curly bracket. a - TRUE if ( a ){ cat(TRUE,\n) } else { cat(FALSE,\n) } Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Shiazy Fuzzy Verzonden: woensdag 20 juni 2007 11:41 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Got Unexpected ELSE error Dear R-users, I have a problem with the IF-ELSE syntax. Please look at the folllowing code and tell me what's wrong: a - TRUE if ( a ) { cat(TRUE,\n) } else { cat(FALSE,\n) } If I try to execute with R I get: Error: syntax error, unexpected ELSE in else The strange thing is either cat instructions are executed!! My system is: Fedora Core 6 x86_64 + R 2.5.0 (rpm) Thank you very much in advance Regards, -- Marco __ 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] Conditional Sequential Gaussian Simulation
Steve, You can do this with the package gstat. Look for ?krige of ?predict.gstat Post further question on this topic on the R-sig-geo list. You'll get more response. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Friedman, Steven Verzonden: donderdag 7 juni 2007 14:46 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Conditional Sequential Gaussian Simulation Hello, I'm wondering if there are any packages/functions that can perform conditional sequential gaussian simulation. I'm following an article written by Grunwald, Reddy, Prenger and Fisher 2007. Modeling of the spatial variability of biogeochemical soil properties in a freshwater ecosystem. Ecological Modelling 201: 521 - 535, and would like to explore this methodology. Thanks Steve Steve Friedman, PhD Everglades Division Senior Environmental Scientist, Landscape Ecology South Florida Water Management District 3301 Gun Club Road West Palm Beach, Florida 33406 email: [EMAIL PROTECTED] Office: 561 - 682 - 6312 Fax: 561 - 682 - 5980 If you are not doing what you truly enjoy its your obligation to yourself to change. [[alternative HTML version deleted]] __ 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] list
Sure you can. list(list(), list(), list()) library(fortunes) fortune(Yoda) Evelyn Hall: I would like to know how (if) I can extract some of the information from the summary of my nlme. Simon Blomberg: This is R. There is no if. Only how. -- Evelyn Hall and Simon 'Yoda' Blomberg R-help (April 2005) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens elyakhlifi mustapha Verzonden: woensdag 6 juni 2007 10:59 Aan: R-help@stat.math.ethz.ch Onderwerp: [R] list hello, I wanna know how to create a list of list if it's possible and if it isn't possible how to do without. thanks. __ ___ [[alternative HTML version deleted]] __ 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] Lines to plots with a for-loop
Dear Taija, You want lines but use points? Try for(i in levels(fHCGB$code)){ with(subset(fHCGB,code==i), plot(pooledPlateIntra, type=b, ylim=ylim, xlab=code, ylab=CV%) lines(fHCGB$limitVarC, col=green)) } Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Saanisto, Taija Verzonden: dinsdag 5 juni 2007 13:12 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Lines to plots with a for-loop Hello all, I'm plotting several graphs with a for-loop with a code: par(mfrow=c(3,4)) for(i in levels(fHCGB$code)) with(subset(fHCGB,code==i), plot(pooledPlateIntra, type=b, ylim=ylim, xlab=code, ylab=CV%)) With which I have no problems.. However I need to add lines to all of these 12 plots, but I cannot get it to work. I've tried for example par(mfrow=c(3,4)) for(i in levels(fHCGB$code)) with(subset(fHCGB,code==i), plot(pooledPlateIntra, type=b, ylim=ylim, xlab=code, ylab=CV%) points(fHCGB$limitVarC,type=b, col=green))) But run into errors. How can the lines be added? Taija Saanisto Biostatistician Quality assurance, Process Development PerkinElmer Life and Analytical Sciences / Wallac Oy Phone: +358-2-2678 741 [[alternative HTML version deleted]] __ 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] getting t.test to work with apply()
Since you are using function(x) the apply function is passing values to x. So you need to use x inside the function. Try something like this: apply(raw.sample,1,function(x){t.test(x[alive],x[dead])}) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Andrew Yee Verzonden: zondag 3 juni 2007 23:49 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] getting t.test to work with apply() Hi, I'm interested in using apply() with t.test() on a data.frame. Specifically, I'd like to use apply() to do the following: t.test(raw.sample[1,alive],raw.sample[1,dead]) t.test(raw.sample[2,alive],raw.sample[2,dead]) t.test(raw.sample[3,alive],raw.sample[3,dead]) etc. I tried the following, apply(raw.sample,1,function(x) t.test(raw.sample[,alive],raw.sample[,dead])) but it gives me a list of identical results. Thanks, Andrew [[alternative HTML version deleted]] __ 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] Abstract plot
You can do than. You just need to specify the strings in the axis-labels. plot(y~x, axes = F) axis(1, at = range(x), labels = c(Xmin, Xmax)) axis(2) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Alberto Monteiro Verzonden: maandag 4 juni 2007 15:19 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Abstract plot I want to make a plot, but instead of showing _numerical_ values, I would like to show _symbolic_ values. For example, I want to plot a function y = a x + b, where x varies between Xmin and Xmax. I would like the plot to show, in the x-axis, the strings Xmin and Xmax, instead of their numeric values. Is it possible? Alberto Monteiro __ 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] getting t.test to work with apply()
Apply passes the row as a vector, not as a dataframe. So you need to remove the colons in x[, alive] and x[, dead] results -apply(raw.sample,1,function(x) t.test(x[alive],x[dead])) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Andrew Yee Verzonden: maandag 4 juni 2007 15:34 Aan: Peter Dalgaard CC: r-help@stat.math.ethz.ch Onderwerp: Re: [R] getting t.test to work with apply() Thanks for everyone's suggestions. I did try results -apply(raw.sample,1,function(x) t.test(x[,alive],x[,dead])) However, I get: Error in x[, alive] : incorrect number of dimensions Full disclosure, raw.sample is a data.frame, and I am using alive and dead as indexing vectors. On the other hand, the lapply suggestion works better. results - lapply(1:nrow(raw.sample), function(i) t.test(raw.sample [i,alive],raw.sample[i,dead])) Thanks, Andrew On 6/4/07, Peter Dalgaard [EMAIL PROTECTED] wrote: Petr Klasterecky wrote: Andrew Yee napsal(a): Hi, I'm interested in using apply() with t.test() on a data.frame. Specifically, I'd like to use apply() to do the following: t.test(raw.sample[1,alive],raw.sample[1,dead]) t.test(raw.sample[2,alive],raw.sample[2,dead]) t.test(raw.sample[3,alive],raw.sample[3,dead]) etc. I tried the following, apply(raw.sample,1,function(x) t.test(raw.sample[,alive],raw.sample [,dead])) Two comments: 1) apply() works on arrays. If your dataframe only has numeric values, turn it (or its copy) to a matrix via as.matrix(). If it has mixed variables, take only the numeric part for t-tests. The conversion is made implicitly but explicit asking for it cannot hurt. 2) the main problem - you are using a wrong argument to t.test The call should look like apply(as.matrix(raw.sample), 1, function(x){t.test(x[alive], x[dead])}) assuming 'alive' and 'dead' are logical vectors of the same length as 'x'. Petr Notice also that the other apply-style functions may give an easier route to the goal: lapply(1:N, function(i) t.test(raw.sample[i,alive],raw.sample[i,dead])) or (maybe, depends on raw.sample being a data frame and alive/dead being indexing vectors) mapply(t.test, raw.sample[,alive], raw.sample[,dead]) but it gives me a list of identical results. Thanks, Andrew [[alternative HTML version deleted]] __ 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. -- 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 [[alternative HTML version deleted]] __ 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] R-help with apply and ccf
You could combine them with cbind, and then split the rows again inside the function you're calling with apply. Mat - cbind(mat1, mat2) apply(Mat, 1, function(x){ row.mat1 - x[seq_len(length(x)/2)] row.mat2 - x[length(x)/2 + seq_len(length(x)/2)] cor(row.mat1, row.mat2) }) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Michael Andric Verzonden: dinsdag 22 mei 2007 17:35 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] R-help with apply and ccf Dear R gurus, I would like to use the ccf function on two matrices that are each 196000 x 12. Ideally, I want to be able to go row by row for the two matrices using apply for the ccf function and get one 196000 X 1 array output. The apply function though wants only one array, no? Basically, is there a way to use apply when there are two arrays in order to do something like correlation on a row by row basis? Thanks for your help Michael [[alternative HTML version deleted]] __ 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] more woes trying to convert a data.frame to a numerical matrix
?as.numeric ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Andrew Yee Verzonden: woensdag 16 mei 2007 14:11 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] more woes trying to convert a data.frame to a numerical matrix I have the following csv file: name,x,y,z category,delta,gamma,epsilon a,1,2,3 b,4,5,6 c,7,8,9 I'd like to create a numeric matrix of just the numbers in this csv dataset. I've tried the following program: sample.data - read.csv(sample.csv) numerical.data - as.matrix(sample.data[-1,-1]) However, print(numerical.data) returns what appears to be a matrix of characters: x y z 2 1 2 3 3 4 5 6 4 7 8 9 How do I force it to be numbers rather than characters? Thanks, Andrew [[alternative HTML version deleted]] __ 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] Help with saptial analysis (cluster)
Dear Fransico, The distance matrix would be 102000 x 102000. So it would contain 1040400 values. If you need one bit for each value, this would requier 9,7 GB. So the distance matrix won't fit in the RAM of your computer. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Francisco Pastor Verzonden: woensdag 25 april 2007 12:34 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Help with saptial analysis (cluster) Hi R-users I'm a beginner with R and statistics, so I need some help to start my data analysis. I've been reading some docs and tutorials on R and cluster analysis. I've got a large dataset (102000 points) with values of longitude, latitude and temperature and want to see if I can find groups (clusters). Following some tutorials I can look for principal components but get an error with calculation of distances: matriz.distancias-dist(comp.obs) Error in vector(double, length) : specified vector size is too big (translated from spanish) So, my questions are: is the dataset too big? could you point me to any docs explaining how to study spatially distributed data (lon,lat,data)? Thanks in advance __ _ Francisco Pastor Meteorology department Fundación CEAM [EMAIL PROTECTED] http://www.gva.es/ceamet http://www.gva.es/ceam Paterna, Valencia, Spain __ _ Usuario Linux registrado: 363952 __ 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] program avail. for simulating spatial patterns?
Have a look at packages in the spatial taskview (spatstat, splancs). Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Wade Wall Verzonden: woensdag 25 april 2007 15:03 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] program avail. for simulating spatial patterns? Hi all, I am wondering if there is a function available in R for simulating spatial distribution of objects (plants in this case) in order to simulate sampling of a population . Specifically, I would like to be able to change the spatial correlation of individuals. I don't want to reinvent the wheel if it already exists. Thanks, Wade __ 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] Matrix or grid conversion of spatial data
Marco, I've done something similar with spatial data. I defined the points as SpatialPoints, the grid as SpatialGrid (using the sp package). Then table(overlay(grid, points)) will give you the number of points inside each gridcell. library(sp) points - SpatialPoints(your.data.frame) cellsize - 1 cellcentre.offset - bbox(points)[, 1] coords.span - diff(t(bbox(points))) cells.dim - ceiling(coords.span / cellsize) grid - SpatialGrid(GridTopology(cellcentre.offset, rep(cellsize, nrow(bbox(points))), cells.dim)) in.cell - overlay(grid, points) table(in.cell) Cheers, Thierry PS R-sig-geo is a better list to ask spatial releated questions. ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Marco Visser Verzonden: woensdag 18 april 2007 20:57 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Matrix or grid conversion of spatial data Dear Happy R-users experts, I am in need of advice, While working with spatial data (x y coordinates of seed locations) I have come accross the problem that I need to convert my point data into a matrix or grid system. I then need to count how often a point falls into a certain position in the matrix or grid. I have searched all day online, asked collegeas but nothing works. Sadly my R box of tricks has run out. My (point) data looks like this; x y 2.34.5 3.4 0.2 and continues for another million records. Now my question; is there any function that is able to count how often a point falls into a grid based on the x and y location? So I need to discretize the spatial locations to a regular grid and then counting how often a point occurs. Many thanks for your thoughts on this problem. Marco Visser __ [[alternative HTML version deleted]] __ 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] Help on averaging sets of rows defined by row name
Dear Marije, I think that aggregate() would make your life a lot easier. aggregate(table.imputed, by = table.imputed[, 1], FUN = mean) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Booman, M Verzonden: vrijdag 20 april 2007 15:27 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Help on averaging sets of rows defined by row name Dear all, This is my problem: I have a table of gene expression data, where 1st column is gene name, and 2nd -39th columns each are exression data for 38 samples. There are multiple measurements per sample for each gene, so there are multiple rows for each gene name. I want to average these measurements so i end up with one value per sample for each gene name. The output data frame (table.averaged) is further used in other R script. The code I use now (see below) takes 20 secs for each loop, so it takes 45 minutes to average my files of 13500 unique genes. Can anyone help me do this faster? Cheers, marije Code I use: table.imputed[,1] - as.character(table.imputed[,1]) #table.imputed is data.frame,1st column = gene name (class factor), rest of columns = expression data (class numeric) genesunique - unique(table.imputed[,1]) #To make list of unique genes in the set table.averaged - NULL for (j in 1:length(genesunique)) { if (j%%100 == 0){ #To report progress cat(j, genes finished, sep= , fill=TRUE) } table.averaged-rbind(table.averaged,givemean(genesunique[j], table.imputed)) #collects all rows of average values and binds them back into one data frame } givemean - function (gene, table.imputed) { thisgene-table.imputed[table.imputed[,1]==gene,] #make a subset containing only the rows for one gene name data.frame(gene,t(sapply(thisgene[,2:ncol(thisgene)],mean, na.rm=TRUE))) #calculates average for each sample (column) and outputs one row of average values and the gene name } De inhoud van dit bericht is vertrouwelijk en alleen bestemd voor de geadresseerde(n). Anderen dan de geadresseerde mogen geen gebruik maken van dit bericht, het openbaar maken of op enige wijze verspreiden of vermenigvuldigen. Het UMCG kan niet aansprakelijk gesteld worden voor een incomplete aankomst of vertraging van dit verzonden bericht. The contents of this message are confidential and only intended for the eyes of the addressee(s). Others than the addressee(s) are not allowed to use this message, to make it public or to distribute or multiply this message in any way. The UMCG cannot be held responsible for incomplete reception or delay of this transferred message. __ 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] Suggestions for statistical computing course
2. I do most of my work in R using Emacs and ESS. That means that I keep a file in an emacs window and I submit it to R one line at a time or one region at a time, making corrections and iterating as needed. When I am done, I just save the file with the last, working, correct (hopefully!) version of my code. Is there a way of doing something like that, or in the same spirit, without using Emacs/ESS? What approach would you use to polish and save your code in this case? For my course I will be working in a Windows environment. While I am looking for simple and effective solutions that do not require installing emacs in our computer lab, the answer you should teach your students emacs/ess on top of R is perfecly acceptable. TINN-R (http://www.sciviews.org/Tinn-R/) could be an alternative for Emacs. But hen you would still have to install it on each computer. And there still is the build-in code editor. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney __ 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] matrix construction
Have a look at ?cbind, ?rbind and ?matrix C - cbind(A, B) C - rbind(A, B) C - matrix(c(0:3, 0:3), ncol = 2) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Schmitt, Corinna Verzonden: maandag 26 maart 2007 11:34 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] matrix construction Hallo, can anyone tell me how I can create a matrix in R? I have two arrays A = c(0:3), B=c(0:3). C should be the matrix. I just found the description that a matrix is just an array with two substricpts. Thanks, Corinna __ 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] Change Axis Size
You need to sed the ylim parameter in the plot function to the range that you need. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens [EMAIL PROTECTED] Verzonden: vrijdag 23 maart 2007 13:41 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Change Axis Size Sorry if this is an obvious question but I have not been able to find the answer. I wish to plot 3 lines on the same plot. However, whichever one I plot first, the axis does not have a big enough range for the other two to be shown in the plot (they get cut off at the top and the bottom). Is there a way to change the range of the y-axis when adding a new line to the plot? Thank you, Alex __ 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] for loop in assigning column names
Have you tried something like df - cbind(df, ObJeCT[, 1:10]) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Luis Ridao Cruz Verzonden: woensdag 21 maart 2007 16:14 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] for loop in assigning column names R-help, I have a data frame (df) and I want to add some columns whose names should correspond to the i index in the loop below. for(i in 1:10) { df$eval(paste(St, as.character(i), sep = )) - ObJeCt[i] } An error message comes out : Error: attempt to apply non-function How can I get around this? I could do something like : df$St2 - NA df$St3 - NA dft$St4 -NA .. and afterwards assign the results of the loop above to the columns df$St2,df$St3,,, The problem is that my object ObJeCt[i] may change in size and definition and therefore a way to systematize the task would be desirable. Thanks in advance version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.1 year 2006 month 12 day18 svn rev40228 language R version.string R version 2.4.1 (2006-12-18) __ 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] Row wise solving an equation
Dear Gunter, I've rewritten your functions. But allow me to give you a few tips: - don't be affraid to use some spacing and indentation. It makes code a lot more readable - I prefer to define all variables in a function or I pass them to the function. In your case would recommend to define the constants p, q, u and v in the function Af. This might be a problem. - Have you considered how the uniroot function would react upon NA values? I've added a check for it in the output function. - Avoid using function names as a variable names like you did with t and q. Cheers, Thierry Af - function(AB, t0){ p - 1 q0 - 1 u - 1 v - 1 q0 * (1 - exp(u * AB[2] * t0)) + p * (1 - exp(v * AB[2] * t0) - AB[1]) } output - function(AB){ if(is.na(AB) 0){ NA } else { uniroot(Af, c(0, ), AB = AB) } } apply(ddt[, 2:3], 1, output) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Eerdekens Gunter Verzonden: dinsdag 20 maart 2007 9:31 Aan: R-help@stat.math.ethz.ch Onderwerp: [R] Row wise solving an equation Hello R-list, How can I row wise solve a function for which the input variables are written in a matrix or a vector and have the calculated output added to the matrix or written in a vector? To specify my case in particular I continue: I would like R to calculate for me a value for 't' which is function of input parameters A and B, which are comprised in a matrix called 'ddt' and some other constants. q,p,u,v in this example. The equation (q*(1-exp(u*B*t))+( p*(1-exp(v*B*t)-A) A and B may sometimes be 'missing values' (NA (not a number)) because there isn't always a result for each time step. The matrix ddt looks like this DatetimeB A t [772,] 12/12/2005 15:27:12 NA NANA [773,] 12/12/2005 16:27:12 5001.2448NA [774,] 12/12/2005 17:27:12 NA NANA [775,] 13/12/2005 13:27:12 70125002.64038000NA [776,] 13/12/2005 14:27:12 NA NANA [777,] 13/12/2005 15:31:28 NA NANA I've tried to calculate t as followed Af-function(i,t){ (q*(1-exp(u*ddt[i,2]*t))+( p*(1-exp(v*ddt[i,2]*t)- ddt[i,3]) Because input B is listed in the second column and input A is listed in the third column of the matrix ddt. The fourth column in ddt is meant for the row wise output values of 't'. To calculate 't' I've tried output-function(i){uniroot(Af,c(0,),i=i)} Uniroot has been used on single input values for A and B and gives good results and I would like to automate this. Therefore I tried to use mapply t-mapply(output,i=i) This seems not work and therefore I'm asking the list: how can I calculate in R the row wise value for 't'? Do you have a quick solution for it? Kind regards, Gunter Eerdekens -- - [EMAIL PROTECTED] -- [[alternative HTML version deleted]] __ 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] Power calculation for detecting linear trend
Erik, I haven't seen an answer to your question, so I'll try to answer it. The problem is that you switched the degrees of freedom. You had: 1 - pf(qf(.95, Vl, 1, ncp = 0), Vl, 1, ncp = Dl) [1] 0.05472242 But it should be: 1 - pf(qf(.95, 1, Vl, ncp = 0), 1, Vl, ncp = Dl) [1] 0.532651 Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Meesters, Erik Verzonden: woensdag 7 maart 2007 15:50 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Power calculation for detecting linear trend Dear people, I've a problem in doing a power calculation. In Fryer and Nicholson (1993), ICES J. mar. Sci. 50: 161-168 page 164 an example is given with the following characteristics T=5, points in time R=5, replicates Var.within=0.1 q=10, a 10% increase per year The degrees of freedom for the test are calculated as Vl=T*R-2=23 and the non-centrality parameter Dl=4.54. Using this they get a power of 0.53, but the result that I'm getting is 0.05472242. I've tried this several ways in R, but I'm not able to come up with the same number. Am I doing something wrong in the calculation of the power? Here's my code: T-5 R-5 sigmasq-0.1 q-10 Vl-(T*R)-2 Dl-(R*(T-1)*T*(T+1)/(12*sigmasq))*(log(1+(q/100)))^2 #Dl result is still similar power.1-1-pf(qf(.95,(T*R-2),1,ncp=0),(T*R-2),1,ncp=Dl) Thank you for any suggestions/help. I'm using R2.4.1, on windowsXP. Erik Meesters [[alternative HTML version deleted]] __ 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 open more windows to make more graphs at once!
Creating more than one graphic windows is, as far as I know, not possible in R. But it's no problem to run a script which create multiply jpeg's. See ?jpeg on how to create jpeg's. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:r-help- [EMAIL PROTECTED] Namens Faramarzi Monireh Verzonden: woensdag 7 maart 2007 9:39 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] How to open more windows to make more graphs at once! Dear R users, I have a data frame (test) including five columns of upper (numeric), lower (numeric), observed (numeric), best_sim (numeric) and stname (factor with 80 levels, each level with different length). Now I would like to write a short program to draw one graph as follow for each level of stname but I would like also to draw each time 12 graphs for the 12 levels of stname in the same graphic windows and save it as jpeg' file . This means at the end I will have 7 (80 levels/12=7) graphic windows and 7 jpeg files each one with 12 graphs (the last one with 8 graphs) for the 12 levels of stname. I already wrote the following script to do it each time for 12 levels of stname but I have to change script each time for the another 12 levels [line 3 in the script for example: for( i in levels(test$stname)[12:24))] and I do not know how can I save the obtained graphs (seven graphic windows) as jpeg files (e.g. plot1.jpeg, plot2.jpeg and so on). As I have 45 dataset like this it would be gr! eat if somebody can help me to complete this script to do all together for a dataset using a script. Thank you very much in advance for your cooperation, Monireh windows(9,9) par(mfrow = c(3,4)) for( i in levels(test$stname)[1:12]) { data- test[test$stname==i,] xx - c(1:length(data$upper), length(data$upper):1) yy - c(data$upper, rev(data$lower)) zz- data$observed tt- data$Best_Sim par(lab =c(10,15,2)) plot.jpeg- plot(xx,yy, type=n, xlim=c(min(xx), max(xx)), ylim=c(min(zz,yy,tt), max(yy,zz,tt)*1.4), main= i, xlab=Month (1990-2002), ylab=Discharge(m3/s), font.axis=6) polygon(xx, yy, col=green, border = NA) lines(zz, col=blue, lwd=1.5) lines(tt,col=red, lwd=1.5) legend(length(zz)-60, max(yy,zz,tt)*1.45, c(Upper Limit, Lower Limit, Observed,Best etimation) , lwd=c(10, 1,1.7,1.7), bty=n, col= c(green, white, blue,red)) } __ 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] Test of Presence Matrix HOWTO?
a - c(A,B,C,D) b - c(A,B,E,F) c - c(A,C,E,G) Df - cbind(a, b, c) apply(Df, 2, function(x)(LETTERS[1:7] %in% x)) a b c [1,] TRUE TRUE TRUE [2,] TRUE TRUE FALSE [3,] TRUE FALSE TRUE [4,] TRUE FALSE FALSE [5,] FALSE TRUE TRUE [6,] FALSE TRUE FALSE [7,] FALSE FALSE TRUE apply(Df, 2, function(x)(as.numeric(LETTERS[1:7] %in% x))) a b c [1,] 1 1 1 [2,] 1 1 0 [3,] 1 0 1 [4,] 1 0 0 [5,] 0 1 1 [6,] 0 1 0 [7,] 0 0 1 Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:r-help- [EMAIL PROTECTED] Namens Johannes Graumann Verzonden: maandag 26 februari 2007 16:25 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Test of Presence Matrix HOWTO? Hello, Imagine 3 lists like so: a - list(A,B,C,D) b - list(A,B,E,F) c - list(A,C,E,G) What I need (vennDiagram) is a matrix characterizing with 1 or 0 whether any given member is present or not like so: x1 x2 x3 [1,] 1 1 1 [2,] 1 1 0 [3,] 1 0 1 [4,] 1 0 0 [5,] 0 1 1 [6,] 0 1 0 [7,] 0 0 1 (where the rows represent A-G and the columns a-c, respectively). table(c(a,b,c)) will give me a quick answer for the 1 1 1 case, but how to deal with the other cases efficiently without looping over each string and looking for membership %in% each list? Thanks for enlightening the learning, Joh __ 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] TRUE/FALSE as numeric values
RSF_EU$AREA[RSF_EU$AREA=x] ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:r-help- [EMAIL PROTECTED] Namens Thomas Preuth Verzonden: vrijdag 23 februari 2007 14:39 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] TRUE/FALSE as numeric values Hello, I want to select in a column of a dataframe all numbers smaller than a value x but when I type in test-(RSF_EU$AREA=x) I receiv as answer: test [1] TRUE FALSE FALSE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE FALSE TRUE TRUE TRUE TRUE TRUE [18] TRUE TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE TRUE [35] FALSE TRUE TRUE TRUE TRUE FALSE FALSE FALSE TRUE TRUE FALSE TRUE TRUE FALSE FALSE TRUE FALSE [52] TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE FALSE TRUE How can i get the values smaller than x and not the TRUE/FALSE reply? Thanks in advance, Thomas __ 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] Trying to get an apply to work with a list in applying names totables
John, Two things. You don't need to pout the cc variable in the apply. Use instead something like this. apply(cc, 2, fn1, y = mylist) But this still doesn't solve your problem. You'll need to rewrite your function like this. fn2 - function(x, y, i){ + tt - table(x[, i]) + names(tt) - y[[i]] + return(tt) + } sapply(1:ncol(cc), fn2, x = cc, y = mylist) [[1]] yes no 2 3 [[2]] a b c d 1 1 2 1 Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens John Kane Verzonden: woensdag 21 februari 2007 16:47 Aan: R R-help Onderwerp: [R] Trying to get an apply to work with a list in applying names totables I am trying to use apply and a list to supply names to a set of tables I want to generate. Below is an example that I hope mimics the larger original problem. EXAMPLE aa - c( 2,2,1,1,2) bb - c(5,6,6,7,4) aan - c(yes, no) bbn - c(a, b, c, d) mynames - c(abby, billy) mylist - list(aan, bbn); names(mylist) - mynames cc - data.frame(aa,bb) fn1 - function(x,y) {tt - table(x); names(tt)- mylist[[y]]} jj -apply(cc, 2, fn1(cc,mylist)) RESULT: Error in fn1(cc, mylist) : invalid subscript type To be honest I didn't expect it to work since that fin1(cc looks recursive but oh well... Can anyone offer a solution or some advice here. It would be greatly appreciated __ 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] categorical column to numeric column
Maybe this isn't the most elegant way, but it should work. dd$g - -1 dd$g[dd$aa == a] - 1 Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Shubha Vishwanath Karanth Verzonden: maandag 19 februari 2007 14:36 Aan: r-help Onderwerp: [R] categorical column to numeric column Hi R, Let 'dd' be a data frame given as: dd=data.frame(aa=c(a,a,b,a,b,b),bb=c(1,1,1,2,3,4)) Now I want to create a column 'g' such that if dd$aa=a then dd$g=1 else dd$g= -1 . So, I gave the below syntax: if((dd$aa)==a) dd$g=1 else dd$g= -1 But I get the error message as: Warning message: the condition has length 1 and only the first element will be used in: if ((dd$aa) == a) dd$g = 1 else dd$g = -1 and dd= dd aa bb g 1 a 1 1 2 a 1 1 3 b 1 1 4 a 2 1 5 b 3 1 6 b 4 1 Please let me know what is the error I am doing? [[alternative HTML version deleted]] __ 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
See ?points, ?lines and ?par (especially par(new = T)). Reading an introduction book about R might be a good idea if you're new. Dalgaard (Introductory Statistics with R) Everitt Hothorn (A Handbook of Statistical Analyses Using R) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Azizi Verzonden: vrijdag 16 februari 2007 12:50 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] plotting Hello, I use newly R! I'd like to plot several data set together in one output window! How can I do that? Best regards Hadi - Never miss an email again! [[alternative HTML version deleted]] __ 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] Is this a correct forum to discuss basic R problem?
?aggregate ?by ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens d. sarthi maheshwari Verzonden: woensdag 14 februari 2007 11:41 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Is this a correct forum to discuss basic R problem? Hi Sorry if this is a wrong post in the forum. Please suggest if this is a correct forum to discuss R related basic problem. I wanted to perform the following task by using R: e.g. input data.frame x y a10 b20 a10 a10 b15 b15 b20 In o/p i need xy = a 30 b 70 Currently i am storing the data.frame as a database table by using sqlSave. Then I am retrieving the data using sqlQuery command. In the query I am using Group by function of SQL. is there any smarter way to this in R? -- thanks Sar [[alternative HTML version deleted]] __ 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] Fatigued R
Dear Shubha, The error message tells you that the error occurs in the line: merge(d_mer,cdaily) And the problem is that d_mer and cdaily have a different class. It looks as you need to convert cdaily to the correct class (same class as d_mer). Don't forget to use traceback() when debugging your program. You code could use some tweaking. Don't be afraid to add spaces and indentation. That will make you code a lot more readable. I noticed that you have defined some variables within your function (lent, t). This might lead to strange behaviour of your function, as it will use the global variables. Giving a variable the same name as a function (t) is confusing. t[2] and t(2) look very similar but do something very different. Sometimes it pays off to covert for-loop in apply-type functions. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Shubha Vishwanath Karanth Verzonden: dinsdag 13 februari 2007 14:51 Aan: Sarah Goslee; r-help@stat.math.ethz.ch Onderwerp: Re: [R] Fatigued R OhkkkI will try to do that now This is my download function... download-function(fil) { con-blpConnect(show.days=show_day, na.action=na_action, periodicity=periodicity) for(i in 1:lent) { Sys.sleep(3) cdaily-blpGetData(con,unique(t[,i]),fil,start=as.chron(as.Date(1/1/199 6, %m/%d/%Y)),end=as.chron(as.Date(12/28/2006, %m/%d/%Y))) #Sys.sleep(3) if(!exists(d_mer)) d_mer=cdaily else d_mer=merge(d_mer,cdaily) rm(cdaily) } dat-data.frame(Date=index(d_mer),d_mer) dat$ABCDEFG=NULL path1-paste(D:\\SAS\\Project2\\Daily\\,fil,_root.sas7bdat,sep=) path2-paste(D:\\SAS\\Project2\\Daily\\CODEFILES\\,fil,.sas,sep=) sasname-paste(x1,fil,',sep=) write.foreign(dat,path1,path2,package=SAS,dataname=sasname) blpDisconnect(con) } for(j in 1:lenf) { fname-paste(D:\\SAS\\Project2\\Daily\\,filename[j],_root.sas7bdat,s ep=) Sys.sleep(600) if(!file.exists(fname)) download(fil=filename[j]) } And lent=58 and lenf=8... 8 text files will be generated in this process if the program would have run properly, and each would be of size 4,000 KB. The error message I get if the program is not run is: Error in dimnames(x) - dn : length of 'dimnames' [2] not equal to array extent In addition: Warning message: Index vectors are of different classes: chron chron dates in: merge(d_mer,cdaily) Please could any one help on this? -Original Message- From: Sarah Goslee [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 13, 2007 7:09 PM To: Shubha Vishwanath Karanth Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Fatigued R Hi Shubha, Perhaps you haven't gotten any help because you haven't provided a reproducible example, or even told us what you are trying to do (specifically) or what errors you are receiving. Frankly, your problem statement doesn't make any sense to me, and I can't provide advice without more information. As the footer of every email says: PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Sarah On 2/13/07, Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote: Hi R, Please solve my problem... I am extracting Bloomberg data from R, in a loop. R is getting fatigued by doing this process and gives some errors. I introduced sleep function. Doing this sometimes I get the results and sometimes not. I even noticed that if I give complete rest for R (don't open R window) for 1 day and then run my code with the sleep function, then the program works. But if I keep on doing this with on R, repeatedly I get errors. Please can anyone do something for this? Is there any function of refreshing R completely.Or any other techniques?...I am really getting bugged with this... Thanks, Shubha -- Sarah Goslee http://www.functionaldiversity.org __ 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
Re: [R] Polygon triangulation?
Have you tried the tri-package? Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Duncan Murdoch Verzonden: dinsdag 13 februari 2007 15:27 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Polygon triangulation? Can anyone point me to a package that contains code to triangulate a polygon? This is easy if the polygon is convex, but tricky if not. One algorithm to do it is due to Meister, and is described here: www.math.gatech.edu/~randall/AlgsF06/planartri.pdf Duncan Murdoch __ 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] Fatigued R
Shubha, You suggested the solution yourself: first make sure that the downloaded data has no errors and reload it when it has errors. But that's something you'll have to do yourself. Have a look at the data downloaded with and without errors and try to see the difference. Again: it's impossible to solve your problem without an example of the correct and faulty data. Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: Shubha Vishwanath Karanth [mailto:[EMAIL PROTECTED] Verzonden: dinsdag 13 februari 2007 16:06 Aan: ONKELINX, Thierry; r-help@stat.math.ethz.ch; [EMAIL PROTECTED] Onderwerp: RE: [R] Fatigued R Hi all, thanks for your reply But I have to make one thing clear that there are no errors in programming...I assure that to you, because I have extracted the data many times from the same program... The problem is with the connection of R with Bloomberg, sometimes the data is not fetched at all and so I get the below errors...It is mainly due to some network jam problems and all... Could anyone suggest me how to refresh R, or how to always make sure that the data is downloaded without any errors for each loop? I tried with Sys.sleep() to give some free time to R...but it is not successful always... Could anybody help me out? Thank you, Shubha -Original Message- From: ONKELINX, Thierry [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 13, 2007 7:56 PM To: Shubha Vishwanath Karanth; r-help@stat.math.ethz.ch Subject: RE: [R] Fatigued R Dear Shubha, The error message tells you that the error occurs in the line: merge(d_mer,cdaily) And the problem is that d_mer and cdaily have a different class. It looks as you need to convert cdaily to the correct class (same class as d_mer). Don't forget to use traceback() when debugging your program. You code could use some tweaking. Don't be afraid to add spaces and indentation. That will make you code a lot more readable. I noticed that you have defined some variables within your function (lent, t). This might lead to strange behaviour of your function, as it will use the global variables. Giving a variable the same name as a function (t) is confusing. t[2] and t(2) look very similar but do something very different. Sometimes it pays off to covert for-loop in apply-type functions. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Shubha Vishwanath Karanth Verzonden: dinsdag 13 februari 2007 14:51 Aan: Sarah Goslee; r-help@stat.math.ethz.ch Onderwerp: Re: [R] Fatigued R OhkkkI will try to do that now This is my download function... download-function(fil) { con-blpConnect(show.days=show_day, na.action=na_action, periodicity=periodicity) for(i in 1:lent) { Sys.sleep(3) cdaily-blpGetData(con,unique(t[,i]),fil,start=as.chron(as.Date(1/1/199 6, %m/%d/%Y)),end=as.chron(as.Date(12/28/2006, %m/%d/%Y))) #Sys.sleep(3) if(!exists(d_mer)) d_mer=cdaily else d_mer=merge(d_mer,cdaily) rm(cdaily) } dat-data.frame(Date=index(d_mer),d_mer) dat$ABCDEFG=NULL path1-paste(D:\\SAS\\Project2\\Daily\\,fil,_root.sas7bdat,sep=) path2-paste(D:\\SAS\\Project2\\Daily\\CODEFILES\\,fil,.sas,sep=) sasname-paste(x1,fil,',sep=) write.foreign(dat,path1,path2,package=SAS,dataname=sasname) blpDisconnect(con) } for(j in 1:lenf) { fname-paste(D:\\SAS\\Project2\\Daily\\,filename[j],_root.sas7bdat,s ep=) Sys.sleep(600) if(!file.exists(fname)) download(fil=filename[j]) } And lent=58 and lenf=8... 8 text files will be generated in this process if the program would have run properly, and each would be of size 4,000 KB. The error message I get if the program is not run is: Error in dimnames(x) - dn : length of 'dimnames' [2] not equal to array extent In addition
Re: [R] RE2: Suddenly Subscript out of bounds
Roderick, I'm not suggesting that you need a script to update R automatically. I don't think it is possible to do that. I just was wondering why you are so eager to update all the packages daily, but still are working with an outdated version of R. Myself, I tend to check the R lists for new updates on R and it's packages. Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Verzonden: dinsdag 13 februari 2007 18:04 Aan: ONKELINX, Thierry CC: r-help@stat.math.ethz.ch Onderwerp: RE2: [R] Suddenly Subscript out of bounds If you tell me how to update R itself automatically, I will go for your advice. I am not aware of any method to do it... Bye Rick ONKELINX, Thierry Thierry.ONKELINX An @inbo.be [EMAIL PROTECTED] Kopie 13.02.2007 15:29 Thema RE: [R] Suddenly Subscript out of bounds You update all packages but not R itself? ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens [EMAIL PROTECTED] Verzonden: dinsdag 13 februari 2007 15:15 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Suddenly Subscript out of bounds Hello Using R Version 2.3.1 I have setup a cronjob to update packages, which worked successfully almost a year (it was called daily). Basically, it runs like this: Sys.getenv(http_proxy) update.packages(ask=F,repos=http://cran.r-project.org;) (the http_proxy environment variable is set prior to the call). All of a sudden, I started to get this error: Error in inherits(x, factor) : subscript out of bounds I have no clue about what this means. Is factor a buggy package? Clearly, that kind of things can happen when you just update things automatically... Any help with be appreciated! Bye Rick __ 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] Linking R with Microsoft SQL Server / Client
Dear Steve, Reading the data shouldn't be a problem with RODBC. I've been doing that plenty of times. I'm not sure about writing, but I suppose you probably will. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Steve Friedman Verzonden: maandag 12 februari 2007 15:15 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Linking R with Microsoft SQL Server / Client Hello My colleagues and I have recently established a large database (40 tables each with greater than 15 variables) in Microsoft's SQL Server 2000. Currently we are accessing this database via SQL client running an Windows XP. Our objectives are many fold including running SQL applications, outputting results to ARC/INFO IMS, production of summarizing tables - graphs and web interfaces for user accessibility. The project is still very much in a design phase. I'm interested in knowing if we can link R directly to the database as it is either stored in SQL Server, or SQL Client, or if we are better off keeping it simple and extracting ascii (csv) files from SQL server prior to processing summarizing and model development. Any insight provided will be greatly appreciated. Steve -- Steve Friedman Computational Ecology and Visualization Laboratory Michigan State University Envisioning Ecosystem Decisions [[alternative HTML version deleted]] __ 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] Finding not-matching rows in tables
That's something for the %in% command. Try this (untested!) tab[(tab$id %in% tabella$id) == FALSE, ] Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Vittorio Verzonden: woensdag 7 februari 2007 14:24 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Finding not-matching rows in tables I have these two dataframes in which 'id' is the key field tabella id nome 1 1 PIEMONTE 2 2 VALLED'AOSTA 3 3 LOMBARDIA 4 4 TRENTINO 5 5VENETO 6 6FRIULI AND tab id nome 1 1 PIEMONTE 2 2 VALLED'AOSTA 3 3 LOMBARDIA 4 4 TRENTINO 5 25 CAMPANIA 6 28 LAZIO Is there any R-one-command able to select the only rows of tab that are not present in tabella, matching the two tables on 'id'? The result should be 5 25 CAMPANIA 6 28 LAZIO I was able to obtain this results by means of the merge command merging the two tables and selecting according to the NA fields, therefore in two steps Ciao Vittorio __ 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] Check for presence of object in group of objects
You need %in% a %in% x d %in% x ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Christoph Heibl Verzonden: woensdag 31 januari 2007 11:01 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Check for presence of object in group of objects Dear List, must be simple, but i got stuck on this... I´ve been trying around for some time, but I could not find a straigthforward way to do this: How can one ask if a certain object is element of a certain group of objects, e.g stored in a vector? x - c(a, b, c) # is there a simple function which returns: is a part of x? TRUE is d part of x? FALSE Thanks a lot Christoph __ 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] Conversion of column matrix into a vector without duplicates
?unique unique(A[, 2]) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Shubha Vishwanath Karanth Verzonden: woensdag 24 januari 2007 14:13 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Conversion of column matrix into a vector without duplicates Hi R, I have a matrix A, A= [,1] [,2] [1,] a u [2,] b v [3,] c x [4,] d x [5,] e x I want to put the 2nd column of this matrix in a vector without duplicates. i.e., my vector v should be (u, v, x), whose length is 3. Can anybody help me on this? Thanks in advance Shubha. [[alternative HTML version deleted]] __ 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] graph results of logistic regression
The code of the function plot.logi.hist is defined in appendix A of the article you referred to. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens [EMAIL PROTECTED] Verzonden: zaterdag 13 januari 2007 21:37 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] graph results of logistic regression I would like to graphically represent the results from a matched-pairs logistic regression. I am looking to represent each variable seperately in a graph, displaying the probability of selection for each. My study is looking at habitat selection in turtles so I am comparing habitat variables to turtle locations compared to paired random points (differences in habitat). Consulting previous questions in R help archives I found a somewhat similar request in september of 2005. A response suggested some representation ideas using R code in a Bulletin of the ESA http://www.esapubs.org/bulletin/backissues/086-1/bulletinjan2005.htm#et (with a correction included in Erratum from volume 86(2) http://www.esapubs.org/bulletin/backissues/086-2/et_bulletin86_2print.pd f As explained the code only tries to efficiently represent raw data in the traditional logistic plot that most ecologist are familiar with. However the code which is plot.logi.hist is not recognized when I tried and I could not find it in any of the packages. I am wondering how to run this code (ie- which package it might be in). Any help would be greatly appreciated. __ 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] R editor vs. Tinn-R
Instead of discussing this odd behaviour of TINN-R, I would prefer a discussion on importing data through the clipboard. In my opinion it isn't a good a idea to import data with the clipboard. I know that it's a quick and dirty way to get your data fast into R. But I see two major drawbacks. First of all you have no chance of checking what data you imported. This is important when you need to check your results a few days (weeks, months or even years) later. A second drawback is that you won't feel the need to store your data in an orderly fashion. Which often leads to a huge pile of junk, instead of a valuable dataset... Cheers, Thierry -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] namens BBands Verzonden: vr 12-1-2007 19:47 Aan: R-Help Onderwerp: Re: [R] R editor vs. Tinn-R On 1/12/07, Martin Becker [EMAIL PROTECTED] wrote: Depending on which button you press in Tinn-R, the clipboard is used to transfer the commands to R, so sometimes you can't rely on the previous contents of the clipboard while using Tinn-R. If you use the (source)-versions of the buttons, the content of the clipboard should be preserved. Something odd is going on. I can confirm that read.delim(clipboard) works from R, but not from Tinn-R. What seems odd is that the contents of the clipboard _are_ preserved after the Tinn-R send, so that a subsequent paste or read.delim(clipboard) from R works correctly. Perhaps Tinn-R restores the contents of the clipboard after sending to R such that the R command runs before the restore takes place? jab -- John Bollinger, CFA, CMT www.BollingerBands.com If you advance far enough, you arrive at the beginning. __ 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] dimensions of a all objects
You need something like this: sapply(objects() , function(x)(dim(eval(parse(text = x) a - rnorm(1) b - matrix(rnorm(4), ncol = 2, nrow = 2) sapply(objects() , function(x)(dim(eval(parse(text = x) $a NULL $b [1] 2 2 Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Farrel Buchinsky Verzonden: dinsdag 9 januari 2007 15:30 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] dimensions of a all objects Why will the following command not work sapply(objects(),dim) What does it say about the objects list? What does it say about the dim command? Likewise, the following also does not work all-ls() for (f in all) print(dim(f)) -- Farrel Buchinsky [[alternative HTML version deleted]] __ 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] setting new working directories
See ?getwd and ?setwd to set the working directory See ?load and ?save to read the workspace. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Bill Shipley Verzonden: donderdag 4 januari 2007 15:42 Aan: R help list Onderwerp: [R] setting new working directories Hello, and Happy New Year. My default working directory is getting very cluttered. I know that I should be using a different working directory for each project (I work in Windows), but do not know how to go about creating different ones and moving back and forth between them. I have read Venables Ripley (Modern Applied Statistics with S-PLUS, 1994) but this seems out of date with respect to this topic and have searched through the documentation but cannot find a clear explanation for doing this. Can someone point me to the proper documentation for creating and using different working directories from within Windows (please, no comments about switching to UNIX...). Thanks. Bill Shipley __ 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] export many plots to one file
I can think of two options: 1. Use R2HTML and save the html output as PDF 2. Use Sweave and compile the LaTeX file to PDF. Search the mailing list archive on how to save the graphs as png or jpeg (as Sweave will standard generate eps or pdf graphs). Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens bogdan romocea Verzonden: donderdag 4 januari 2007 17:35 Aan: r-help Onderwerp: [R] export many plots to one file Dear useRs, I have a few hundred plots that I'd like to export to one document. pdf() isn't an option, because the file created is prohibitively huge (due to scatter plots with many points). So I have to use png() instead, but then I end up with a lot of files (would prefer just one). 1. Is there a way to have pdf() embed images, instead of vector instructions? (What would have to be changed/added, and where? I'd consider that a very useful feature.) 2. Does anyone have a script for importing many images (png, bitmap, jpg) into one PDF file? I'd prefer something that works both on Windows and GNU. Thank you, b. __ 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] understanding integer divide (%/%)
This is due to the internal representation of 0.1, which is not exactly 0.1 but very close to it. If you want to do an integer divide, you should only use integers to divide with. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Jeffrey Prisbrey Verzonden: woensdag 3 januari 2007 14:21 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] understanding integer divide (%/%) I am confused about why the following occurs: version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.0 year 2006 month 10 day03 svn rev39566 language R version.string R version 2.4.0 (2006-10-03) 1 %/% 0.1 [1] 9 10 %/% 1 [1] 10 This effect led me into an trap when I tried to classify a set of proportions based on the first decimal place by integer dividing by 0.1. Can someone explain why this behavior occurs and give me an insight into how to predict it? Thanks, -- Jeff __ 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] error: too many open devices
dev.list() will give a list with all open devices. dev.off() will close the current device. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Guillermo Acosta Verzonden: dinsdag 5 december 2006 5:49 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] error: too many open devices Hello all-- I've been using 1.13 (v1915) on my Mac pretty intensly for about a month, but today when I tried to generate a plot I recieved this message: Error in quartz(width=9) : too many open devices I was caught by surprise, because I only had the R console open at the time. I checked to be sure, by clicking Window at the top bar, and R console was the only window open. I thought I had a problem in the workspace, so I switched to a different one that worked earlier today, but the error was there too. I tried clearing the workspace entirely, and creating a single vector and plotting that, but again I got this error about too many open devices. I even quit R, closed everything I had, and restarted... but this error is still there. Has anybody seen this before? I'm sure it's a pretty simple fix, except I've run out of the places that I can think to look. Many thanks in advance, Sincerely, Guillermo Acosta Graduate Student Department of Physics and Astronomy Brigham Young University __ 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] barplot help needed
Is the length of all your datasets equal? If not try etype - rep(c(sd1, sd2, sd3, sd4), c(length(data1), length(data2), length(data3), length(data4)) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Antje Verzonden: vrijdag 24 november 2006 13:42 Aan: r-help@stat.math.ethz.ch Onderwerp: Re: [R] barplot help needed Thank you very much for your help. I just don't understand the following line (which also gives me a dimension error later in the arrows command) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) Antje (I don't see my emails to the mailinglist anymore... just the answers from other people... I don't understand???) Jacques VESLOT schrieb: tab - do.call(rbind, list(data1, data2, data3, data4)) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ 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-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] Fwd: Dates Conversion/write.foreign
Correct me if I'm wrong, but a few weeks ago my professor from the statistical computing class told us that SAS sometimes stores dates including the time but only displays the date. So it looks like the time isn't stored. This was the case with data imported from Excel. In our exercise we had to explicitly define the date as a day, month and year. So maybe you don't have a problem at all ;-) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Shubha Karanth Verzonden: vrijdag 24 november 2006 15:32 Aan: r-help@stat.math.ethz.ch; [EMAIL PROTECTED]; [EMAIL PROTECTED] Onderwerp: [R] Fwd: Dates Conversion/write.foreign -- Forwarded message -- From: Shubha Vishwanath Karanth [EMAIL PROTECTED] Date: Nov 24, 2006 7:54 PM Subject: Dates Conversion/write.foreign To: Shubha Karanth [EMAIL PROTECTED], Shubha Vishwanath Karanth [EMAIL PROTECTED] Hi R experts, I need an urgent help... I have an a dataframe caled idat. Below i give a snapshot of it. Datetime Volume_a Volume_b (11/21/06 12:50:00) (11/21/06 12:50:00) 00 (11/21/06 13:00:00) (11/21/06 13:00:00) 00 (11/21/06 13:10:00) (11/21/06 13:10:00) 00 (11/21/06 13:20:00) (11/21/06 13:20:00) 00 (11/21/06 13:30:00) (11/21/06 13:30:00) 342113 0 (11/21/06 13:40:00) (11/21/06 13:40:00) 695071 0 (11/21/06 13:50:00) (11/21/06 13:50:00) 470943 4690 (11/21/06 14:00:00) (11/21/06 14:00:00) 870072 0 (11/21/06 14:10:00) (11/21/06 14:10:00) 1010101 2000 (11/21/06 14:20:00) (11/21/06 14:20:00) 71428750 (11/21/06 14:30:00) (11/21/06 14:30:00) 388716 1780 (11/21/06 14:40:00) (11/21/06 14:40:00) 380038 1245 The type of each variable is given below: idat : 'data.frame':144 obs. of 3 variables: $ Datetime :Classes 'chron', 'dates', 'times' atomic [1:144] 13473 13473 13473 13473 13473 ... $ Volume_a : num 0 0 0 0 0 0 0 0 0 0 ... $ Volume_b : num 0 0 0 0 0 0 0 0 0 0 ... The variable i am interested is Datetime. I exported this dataframe into SAS by the write.foreign command, write.foreign(idat,Z:\\New\\idat_d.sas7bdat,Z:New\\idat_c.sas,packag e=SAS,dataname=f.idat) When I export, i see only the date value (Note: no time) in my SAS data set. Why is this? The write.foreign package says: Numeric variables and factors are supported for all packages, dates and times (Date, dates, date, and POSIXt classes) are also supported for SAS and characters are supported for SPSS. So, what should i do to get my time value also apart from the datevalue? Do i need to convert the chron object, Datetime into POSIXt...or anything alse...so that SAS can read it as datetime. format? Thank you, Shubha. __ 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] barplot help needed
The arrows are messed up because they are partially outside the borders of the barplot. Try adding a good ylim to the barplot. Something like: b - barplot(tab, beside=T, ylim = c(0, 8)) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Antje Verzonden: vrijdag 24 november 2006 16:17 Aan: r-help@stat.math.ethz.ch Onderwerp: Re: [R] barplot help needed Still, there is one problem. The SD-Values don't fit to the bar they belong to. I made the following experiment: data1 - c(2,4,6,2,5) data2 - data1 sd1 - c(0.5,1,1.5,1,2) sd2 - sd1 tab - do.call(rbind, list(data1, data2)) etype - c(sd1,sd2) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) I expect the bars with the same height and the same stddev. The height is okay, but the stddev is messed up... if I do it like this: etype - matrix(c(sd1,sd2), nrow=2, byrow=TRUE) it works (but maybe there is an easier way...) Antje Jacques VESLOT schrieb: thought sd1, sd2... were scalars but if not just do: etype - c(sd1, sd2, sd3, sd4) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : Thank you very much for your help. I just don't understand the following line (which also gives me a dimension error later in the arrows command) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) Antje (I don't see my emails to the mailinglist anymore... just the answers from other people... I don't understand???) Jacques VESLOT schrieb: tab - do.call(rbind, list(data1, data2, data3, data4)) etype - rep(c(sd1, sd2, sd3, sd4), length(data1)) b - barplot(tab, beside=T) arrows(unlist(b), unlist(tab) - etype, unlist(b), unlist(tab) + etype, code=3) --- Jacques VESLOT CNRS UMR 8090 I.B.L (2ème étage) 1 rue du Professeur Calmette B.P. 245 59019 Lille Cedex Tel : 33 (0)3.20.87.10.44 Fax : 33 (0)3.20.87.10.31 http://www-good.ibl.fr --- Antje a écrit : hello, I would like to create the following barplot: I have 4 different data sets (same length + stddev for each data point) data1 sd1 data2 sd2 data3 sd3 data4 sd4 now, I'd like to plot in the following way: data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side at one x-axis label (named position 1) and each bar in different colors. data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named position 2) with the same color scheme and so on over the whole length. I managed to plot one set in the following way: par(mai=c(1.5,1,1,0.6)) plotInfo - barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = Percentage) arrows(plotInfo,data1,plotInfo, data1 + sd1, length=0.1, angle=90) arrows(plotInfo,data1,plotInfo, data1 - sd1, length=0.1, angle=90) could anybody give me a help on this? Antje __ 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-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,
Re: [R] t.test()
There is no such thing as an unpaired t-test. A t-test can be a paired, one sample or two sample t-test. Since you want to compare the sample against a given mean, you need a one sample t-test. You tried to do a two sample test. That didn't work because you need at least two observations in each group. x - c(23,25,29,27,30,30) t.test(x[-1], mu = x[1]) One Sample t-test data: x[-1] t = 5.3634, df = 4, p-value = 0.005833 alternative hypothesis: true mean is not equal to 23 95 percent confidence interval: 25.50814 30.89186 sample estimates: mean of x 28.2 Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Robin Hankin Verzonden: donderdag 23 november 2006 14:12 Aan: [EMAIL PROTECTED] Onderwerp: [R] t.test() Hi I have a vector x of length n. I am interested in x[1] being different from the other observations (ie x[-1]). My null hypothesis is that x[1] is drawn from a Gaussian distribution of the same mean as observations x[-1], which are assumed to be iid Gaussian. The (unknown) variance of x[1] is assumed to be the same as the variance of x[-1]. This should be an unpaired t-test. But x - c(23,25,29,27,30,30) t.test(x=x[1] , y=x[-1]) Error in t.test.default(x = x[1], y = x[-1]) : not enough 'x' observations What arguments do I need to send to t.test() to test my null? -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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] dividing vectors into bins with equal widths
Hi Daniel, Make sure to include working code and list all needed packages. I couldn't run your code on my machine. If you want equal data points in each class, then you could take every n point from the sorted vector. This example generates the breakpoints to divide a vector in 10 parts. x - floor(rnorm(100) * 10) x [1] -2 9 -12 3 11 7 6 -4 -16 -1 1 -7 -7 7 4 -4 -7 13 1 9 10 1 11 19 -19 -3 12 -6 5 -7 1 -13 -15 [34] 11 -8 -2 -13 10 6 8 15 4 0 -4 12 5 -2 -3 9 -17 -5 9 0 3 7 7 8 -14 -12 -4 -4 -24 -4 4 16 5 [67] 6 -8 -7 -14 -8 -4 -9 18 -2 11 11 -16 -2 2 -1 -8 10 2 21 -9 1 -3 -17 -4 10 -5 -14 7 -13 -6 8 -4 -2 [100] -2 NBreaks - 10 sort(x)[NBreaks * (1:(length(x) / NBreaks - 1))] [1] -14 -8 -5 -3 -1 2 6 9 11 Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens W. Daniel Kissling Verzonden: dinsdag 14 november 2006 13:52 Aan: r-help@stat.math.ethz.ch CC: [EMAIL PROTECTED] Onderwerp: [R] dividing vectors into bins with equal widths Hi R-users, I am trying to divide a vector (say X) into equal frequency bins. If one uses the hist() function, then a histogram is plotted, but with bins of equal widths, and not with bins having the same number of data points. I have then tried the histogram() function as follows: histogram(X, nint=10, breaks=NULL, equal.widths=F) This works as I want. However, I can't extract which points are in which bin, or where the breakpoints are made. Can anybody help? Thanks Daniel W. Daniel Kissling Institut für Zoologie, Abteilung Ökologie Johannes Gutenberg-Universität Mainz D-55099 Mainz, Germany E-mail: [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.
[R] Simplifying Sweave graphics
Dear all, I was wondering if it's possible to simplify graphs created with Sweave. I'm using in a document several plots with each about 4000 points (qqnorm(rnorm(4000))). It looks likes the information of each points is maintained in the graph. As a result of that the pdf filesize get's quite large (about 4,2 MB for a 23 page document.) Is there a way to reduce the complexity of these graphs? Like creating the graphs in a bitmap format instead of a vector format? Thanks, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] www.inbo.be http://www.inbo.be/ Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney [[alternative HTML version deleted]] __ 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] Power of test
A quick answer to your questions: 1. Since nobody knows the true delta. I prefer to calculate the power for a range of deltas. Most of the time for a range spanning - 2 * expected delta up to 2 * expected delta. This gives an idea on how the power changes if delta changes. 2. ?power.t.test explains how to calculate n for a given power, delta, sd and sig.level. A quote from ?power.t.test: Exactly one of the parameters 'n', 'delta', 'power', 'sd', and 'sig.level' must be passed as NULL, and that parameter is determined from the others. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Ethan Johnsons Verzonden: vrijdag 27 oktober 2006 16:59 Aan: Peter Dalgaard CC: r-help@stat.math.ethz.ch Onderwerp: Re: [R] Power of test Thank you so mcuh for the explanation, Chuck Peter. Two quick questions,please. It states that delta = True difference in means. When the true diff is unkown, can you use the expected diff for delta. If you want to know the n (number of observations) off of power.t.test to have i.e. 80% power, how do you calculate? Is there a way to do it in R, or use algebra? power.t.test(n = NULL, delta = NULL, sd = 1, sig.level = 0.05, power = NULL, type = c(two.sample, one.sample, paired), alternative = c(two.sided, one.sided), strict = FALSE) Thank you, ej On 27 Oct 2006 16:37:08 +0200, Peter Dalgaard [EMAIL PROTECTED] wrote: Ethan Johnsons [EMAIL PROTECTED] writes: What would be the R formulae for a two-sided test? I have a formula for a one-sided test: powertest - function(a,m0,m1,n,s){ t1 = -qnorm(1-a) num = abs(m0-m1) * sqrt(n) t2 = num/s pow = pnorm(t1 + t2) } Would you pls let me know if you know of? (Notice that power.t.test does this more accurately) For practical purposes, just halve a. Perfectionists may want you to add pnorm(t1 - t2), so that the total power becomes a when t2 == 0. BTW: -qnorm(1-a)==qnorm(a) -- 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@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] simplification of code using stamp?
I think your script is slow because it has to recalculate the same model five times. I've tried to avoid this by rewriting your function(df). function(df){ fit - summary(lm(distance ~ generation, data=df)) result - c(fit$$r.squared, $coefficients[2], $coefficients[4], $coefficients[1], $coefficients[3]) names(result) - c(rsqs, slope, d.slope, intercept, d.intercept), } Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Rainer M Krug Verzonden: woensdag 25 oktober 2006 11:22 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] simplification of code using stamp? Hi I have the following code which I would like to simplify. Id does linear regressions and returns the r-squares, and the coefficients. It runs slow, as it is doing the regressions for each - is it possible to get the values in a dataframe which looks as follow: expert | xx | seeds | r.squared | slope | intercept Thanks in advance, Rainer library(reshape) rsqs - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$r.squared, silent=TRUE ) ) ) slope - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$coefficients[2], silent=TRUE ) ) ) d.slope - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$coefficients[4], silent=TRUE ) ) ) intercept - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$coefficients[1], silent=TRUE ) ) ) d.intercept - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$coefficients[3], silent=TRUE ) ) ) -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)21 808 3304 Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [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] simplification of code using stamp?
Resending the function because of a typo in the result vector. function(df){ fit - summary(lm(distance ~ generation, data=df)) result - c(fit$r.squared, fit$coefficients[2], fit$coefficients[4], fit$coefficients[1], fit$coefficients[3]) names(result) - c(rsqs, slope, d.slope, intercept, d.intercept), } Cheers, Thierry - ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens ONKELINX, Thierry Verzonden: woensdag 25 oktober 2006 11:36 Aan: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Onderwerp: Re: [R] simplification of code using stamp? I think your script is slow because it has to recalculate the same model five times. I've tried to avoid this by rewriting your function(df). function(df){ fit - summary(lm(distance ~ generation, data=df)) result - c(fit$$r.squared, $coefficients[2], $coefficients[4], $coefficients[1], $coefficients[3]) names(result) - c(rsqs, slope, d.slope, intercept, d.intercept), } Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Rainer M Krug Verzonden: woensdag 25 oktober 2006 11:22 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] simplification of code using stamp? Hi I have the following code which I would like to simplify. Id does linear regressions and returns the r-squares, and the coefficients. It runs slow, as it is doing the regressions for each - is it possible to get the values in a dataframe which looks as follow: expert | xx | seeds | r.squared | slope | intercept Thanks in advance, Rainer library(reshape) rsqs - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$r.squared, silent=TRUE ) ) ) slope - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$coefficients[2], silent=TRUE ) ) ) d.slope - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$coefficients[4], silent=TRUE ) ) ) intercept - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$coefficients[1], silent=TRUE ) ) ) d.intercept - as.data.frame( stamp( tc.long, expert * xx * seeds ~ ., function(df) try( summary( lm(distance ~ generation, data=df))$coefficients[3], silent=TRUE ) ) ) -- Rainer M. Krug, Dipl. Phys. (Germany), MSc Conservation Biology (UCT) Department of Conservation Ecology and Entomology University of Stellenbosch Matieland 7602 South Africa Tel:+27 - (0)72 808 2975 (w) Fax:+27 - (0)21 808 3304 Cell: +27 - (0)83 9479 042 email: [EMAIL PROTECTED] [EMAIL PROTECTED
Re: [R] RODBC sqlQuery insert slow
Large for loops are slow. Try to avoid them using apply, sapply, etc. I've made the paste statements a lot shorter by using collapse. See ?paste for more info. Append.SQL - function(x, channel){ sql=INSERT INTO logger (time, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) VALUES(d1=strptime(x[2],%d/%m/%y %H:%M:%S %p ', d1, ' ,, paste(x[3:12], collapse = , ), ) ) sqlQuery(channel, sql) } ntry=dim(ti)[1] date() nbefore=sqlQuery(channel,SELECT COUNT(*) FROM logger) apply(ti, 2, Append.SQL, channel = channel) nafter=sqlQuery(channel,SELECT COUNT(*) FROM logger) nadded=nafter-nbefore;nadded date() ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be Do not put your faith in what statistics say until you have carefully considered what they do not say. ~William W. Watt A statistical analysis, properly conducted, is a delicate dissection of uncertainties, a surgery of suppositions. ~M.J.Moroney -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Bill Szkotnicki Verzonden: vrijdag 13 oktober 2006 15:09 Aan: [EMAIL PROTECTED] Onderwerp: [R] RODBC sqlQuery insert slow Hello, I am trying to insert a lot of data into a table using windows R (2.3.1) and a mysql database via RODBC. First I read a file with read.csv and then form sql insert statements for each row and execute the insert query one row at a time. See the loop below. This turns out to be very slow. Can anyone please suggest a way to speed it up? Thanks, Bill # R code ntry=dim(ti)[1] date() nbefore=sqlQuery(channel,SELECT COUNT(*) FROM logger) for (i in 1:ntry) { sql=INSERT INTO logger (time,v1,v2,v3,v4,v5,v6,v7,v8,v9,v10) VALUES( d1=strptime(ti[i,2],%d/%m/%y %H:%M:%S %p) sql=paste(sql,',d1,' ) sql=paste(sql,,,ti[i,3] ) sql=paste(sql,,,ti[i,4] ) sql=paste(sql,,,ti[i,5] ) sql=paste(sql,,,ti[i,6] ) sql=paste(sql,,,ti[i,7] ) sql=paste(sql,,,ti[i,8] ) sql=paste(sql,,,ti[i,9] ) sql=paste(sql,,,ti[i,10]) sql=paste(sql,,,ti[i,11]) sql=paste(sql,,,ti[i,12]) sql=paste(sql,) ) #print(sql) sqlQuery(channel, sql) } nafter=sqlQuery(channel,SELECT COUNT(*) FROM logger) nadded=nafter-nbefore;nadded date() __ 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] Beginner question: select cases
Your problem would be a lot easier if you coded the location in one variable instead of three variables. Then you could calculate the means with one line of code: by(results$q1, results$location, mean) With your dataset you could use by(results$London, results$location, mean) by(results$Rome, results$location, mean) by(results$Vienna, results$location, mean) see ?by for more information And take a good look at your code. You take a subset from results and the assign it to results. This means that you replace the original results dataframe with a subset of it. As you take the subset for the next city, you won't take a subset from the original dataset but for the previous subset! Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Peter Wolkerstorfer - CURE Verzonden: maandag 25 september 2006 13:51 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Beginner question: select cases Hello all, I hope i chose the right list as my question is a beginner-question. I have a data set with 3 colums London, Rome and Vienna - the location is presented through a 1 like this: London RomeVienna q1 0 0 1 4 0 1 0 2 1 0 0 3 I just want to calculate the means of a variable q1. I tried following script: # calculate the mean of all locations results - subset(results, subset== 1 ) mean(results$q1) # calculate the mean of London results - subset(results, subset== 1 , select=c(London)) mean(results$q1) # calculate the mean of Rome results - subset(results, subset== 1 , select=c(Rome)) mean(results$q1) # calcualate the mean of Vienna results - subset(results, subset== 1 , select=c(Vienna)) mean(results$q1) As all results are 1.68 and there is defenitely a difference in the three locations I wonder whats going on. I get confused as the Rcmdr asks me to overwrite things and there is no just filter option. Any help would be apprechiated. Thank you in advance. Regards Peter ___CURE - Center for Usability Research Engineering___ Peter Wolkerstorfer Usability Engineer Hauffgasse 3-5, 1110 Wien, Austria [Tel] +43.1.743 54 51.46 [Fax] +43.1.743 54 51.30 [Mail] [EMAIL PROTECTED] [Web] http://www.cure.at __ 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] RODBC Connections closed automatically in background
Usually I try to do all data import before I do long calculations. A simple workaround for your problem would be: foo - function(dsn) { db - odbcConnect(dsn) odbcSetAutoCommit(db, FALSE) data - someDatabaseOperation(db) odbcClose(db) data2 - someLongCalculation(data) db - odbcConnect(dsn) odbcSetAutoCommit(db, FALSE) anotherDatabaseOperation(db, data2) odbcClose(db) } An other options is to include the odbcConnect and odbcClose into someLongCalculation() and anotherDatabaseOperation() Cheers, Thierry -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Jay Z Verzonden: woensdag 20 september 2006 0:12 Aan: R-help@stat.math.ethz.ch Onderwerp: [R] RODBC Connections closed automatically in background I am having a problem with RODBC's connections. It appears that my connection to the database is closed by R automatically before I am done with it. Here is my code: foo - function(dsn) { db - odbcConnect(dsn) odbcSetAutoCommit(db, FALSE) data - someDatabaseOperation(db) data2 - someLongCalculation(data) anotherDatabaseOperation(db, data2) # This often fails b/c the db is no longer open. odbcClose(db) } I see some output: Warning: closing unused RODBC handle 9 Warning: [RODBC] Error SQLDisconnect Warning: [RODBC] Error SQLFreeconnect Warning: [RODBC] Error in SQLFreeEnv Error in odbcGetErrMsg(channel) : first argument is not an open RODBC channel I suspect that during the call to someLongCalculation(), R considers the database connection as unused, and therefore, closes the connection, which prevents me from using the connection in the call to anotherDatabaseOperation(). What causes the database connection to close? What can I do to prevent the connection from closing implicitly? I am using R 2.3.1 on Windows with the latest version of RODBC, connnectin to SQL Server 2000. Thanks in advance. __ 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] Simulation help
This should work. I try to avoid for loops because large (or nested) for loops tend to consume a lot of memory. one.dataset - function(dummy = 0, slope = 0.01){ return(c(yr1= mean(rbinom(50,1,.5)), yr2 =mean(rbinom(50,1,.5 + slope)), yr3 =mean(rbinom(50,1,.5 + 2 * slope)), yr4 =mean(rbinom(50,1,.5 + 3 * slope)), yr5 =mean(rbinom(50,1,.5 + 4 * slope } datasets.slope01 - t(sapply(1:100, one.dataset, slope = 0.01)) datasets.slope05 - t(sapply(1:100, one.dataset, slope = 0.05)) Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Zodet, Marc W. (AHRQ) Verzonden: woensdag 20 september 2006 15:29 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Simulation help I'm trying to simulate trend data over a five year period. I want different trend profiles...the simplest being a linear trend. I've been using the following code: patBdta1 - NULL for(i in 1:100) patBdta1 - rbind(patBdta1,c(yr1= mean(rbinom(50,1,.50)), yr2 =mean(rbinom(50,1,.51)), yr3 =mean(rbinom(50,1,.52)), yr4 =mean(rbinom(50,1,.53)), yr5 =mean(rbinom(50,1,.54 This code creates 100 data sets each with a 5 yr binomial trend profile with a slope of approximately .01. Now, what I want to do is pass this code (or some code) in such a way that I can simulate various trend slopes (i.e., pass in a loop or vectorize vs. copying/repeating code for each slope). Any guidance is much appreciated. Thanks! Marc Marc W. Zodet, MS Senior Health Statistician Agency for Healthcare Research and Quality [[alternative HTML version deleted]] __ 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] Using XY location data to calculate ecological parameters
Assuming you only use the X direction to split the data into 10 m cells. table(list(Species, round(X, digits = -1))) This will generate a table with the number of seedlings per species in each 10 m cell. Divide this by the area of each cell and you get the densities. Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens James R. Milks Verzonden: dinsdag 12 september 2006 15:36 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] Using XY location data to calculate ecological parameters Dear R gurus, I have XY data giving the locations of tree seedlings that were surveyed during a 210 meter belt transect. This belt transect was taken by stretching a line across the field, then measuring all seedlings within 1 meter on either side of the line. The end result was XY coordinates and height for ~1,300 seedlings. I would like to use that data to calculate density of seedlings per 10 meters per species and relative species abundance in order to compare between this transect and other transects as well as to compare between segments of the same transect. Are there any R packages out there that will allow me make those calculations? To give an idea of my data, here's a fictional example: Species X (m) Y(m) Acer negundo90.10 -.19 Acer negundo90.14 -.90 Acer saccharinum90.25 .54 Acer rubrum 90.89 .21 Acer negundo91.25 .36 Acer negundo91.46 -.65 etc. Thanks. Jim Milks __ 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] levels of factor when subsetting the factor
factor(new.fact) will do the trick. But that will recode the levels and that might be something you don't want. fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C factor(new.fact) [1] A A A B B B Levels: A B Cheers, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Reseach Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 [EMAIL PROTECTED] www.inbo.be -Oorspronkelijk bericht- Van: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Namens Afshartous, David Verzonden: dinsdag 12 september 2006 17:23 Aan: r-help@stat.math.ethz.ch Onderwerp: [R] levels of factor when subsetting the factor All, When I take a subset of a factor the reduced factor still maintains all the original levels of the factor when say forming the key in a plot. The data is correct, but the variable still remembers the original levels. See below for reproducible code. Does anyone know how to fix this? cheers, dave fact = as.factor(c(rep(A, 3),rep(B, 3), rep(C, 3))) new.fact = fact[1:6] new.fact [1] A A A B B B Levels: A B C## should only show A B __ 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.