Re: [R] Handling of factors
On Tue, 20 Jan 2009, Stavros Macrakis wrote: I'm rather confused by the semantics of factors. snip actual confusion It is all very confusing. Of course, most of this behavior is documented and is easily determined by experimentation, but it would be easier to learn and teach the language if there were some clear principle underlying all this. What am I missing? No, it really is confusing. The problem is that there are two conflicting clear principles. Factors could be - integer variables with labels (similar to value labels in Stata/SPSS or C enums) - variables that takes on values from a pre-specified set, implemented using integer codes (like Pascal enumerated types). [In fact, there was historically even a third way to view factors, as way to reduce the memory use of string variables. That's obsolete now.] That is, the fact that they are small integers can be seen as part of the interface or just as part of the implementation. It's obvious which one is right, but unfortunately it is differently obvious to different people. AFAIK there has never been a unified policy on this, dating back before R, so different functions behave differently. There have been changes in R over the years, mostly in the direction of making factors more like Pascal enumerations. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] merging several dataframes from a list
Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Handling of factors
As a follow-up, I don't see any reason why rle() shouldn't work on factors. There's no ambiguity about what the result should be, and the current implementation in rle() would work on factors if they could get past the pre-test. -thomas On Wed, 21 Jan 2009, Thomas Lumley wrote: On Tue, 20 Jan 2009, Stavros Macrakis wrote: I'm rather confused by the semantics of factors. snip actual confusion It is all very confusing. Of course, most of this behavior is documented and is easily determined by experimentation, but it would be easier to learn and teach the language if there were some clear principle underlying all this. What am I missing? No, it really is confusing. The problem is that there are two conflicting clear principles. Factors could be - integer variables with labels (similar to value labels in Stata/SPSS or C enums) - variables that takes on values from a pre-specified set, implemented using integer codes (like Pascal enumerated types). [In fact, there was historically even a third way to view factors, as way to reduce the memory use of string variables. That's obsolete now.] That is, the fact that they are small integers can be seen as part of the interface or just as part of the implementation. It's obvious which one is right, but unfortunately it is differently obvious to different people. AFAIK there has never been a unified policy on this, dating back before R, so different functions behave differently. There have been changes in R over the years, mostly in the direction of making factors more like Pascal enumerations. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thomas Lumley Assoc. Professor, Biostatistics tlum...@u.washington.eduUniversity of Washington, Seattle __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Can I add a point to a pointsGrob from an xyplot without redrawing ?
Hi: I am a newbie using grid and lattice. I want to update a xyplot without redrawing and I was wondering if there is a way of adding a point to a pointsGrob ? For example, take the example from the R Graphics Book page 218-219: grid.newpage() angle - seq(0, 2*pi, length=21)[-21] x - cos(angle) y - sin(angle) xyplot( y ~ x, aspect = 1) Lets say I take the pointsGrob below: getNames() [1] GRID.rect.748 plot1.xlabplot1.ylab GRID.segments.749 [5] GRID.segments.750 GRID.text.751 GRID.segments.752 GRID.text.753 [9] GRID.segments.754 GRID.points.755 GRID.rect.756 pg = grid.get(GRID.points, grep=TRUE) pg points[GRID.points.755] Is there a way I can add a point to pg (or GRID.points.755) to update the xyplot without redrawing all the points ? If redrawing is obligatory, is there way of redrawing the least elements of the xyplot ? Searched for a long time but could not find anything, even if this seems like a fairly basic operation. I guess this may well go against the grid's package philosophy or architecture ? Thanks. Daniel. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging several dataframes from a list
What version of R are you using? I get this: do.call(cbind, mylist) df1.pos df1.data df2.pos df2.data df3.pos df3.data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 R.version.string [1] R version 2.8.1 Patched (2008-12-26 r47350) In which case ALL - do.call(cbind, mylist) ALL - ALL[regexpr(data, names(ALL)) 0] names(ALL) - sub([.].*, , names(ALL)) ALL df1 df2 df3 1 2 6 9 2 6 2 3 3 3 9 6 4 1 7 2 5 9 5 1 On Wed, Jan 21, 2009 at 3:19 AM, Antje niederlein-rs...@yahoo.de wrote: Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging several dataframes from a list
Gabor Grothendieck schrieb: What version of R are you using? R version 2.8.1 (2008-12-22) (running Windows) I get this: do.call(cbind, mylist) df1.pos df1.data df2.pos df2.data df3.pos df3.data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 R.version.string [1] R version 2.8.1 Patched (2008-12-26 r47350) In which case ALL - do.call(cbind, mylist) ALL - ALL[regexpr(data, names(ALL)) 0] names(ALL) - sub([.].*, , names(ALL)) ALL df1 df2 df3 1 2 6 9 2 6 2 3 3 3 9 6 4 1 7 2 5 9 5 1 On Wed, Jan 21, 2009 at 3:19 AM, Antje niederlein-rs...@yahoo.de wrote: Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can I add a point to a pointsGrob from an xyplot without redrawing ?
Hi Daniel, Is there a way I can add a point to pg (or GRID.points.755) to update the xyplot without redrawing all the points ? I think you want to look at ?grid.edit to do this. grid.edit(yourGROB, redraw = FALSE) HTH, Mark. Daniel Kornhauser-3 wrote: Hi: I am a newbie using grid and lattice. I want to update a xyplot without redrawing and I was wondering if there is a way of adding a point to a pointsGrob ? For example, take the example from the R Graphics Book page 218-219: grid.newpage() angle - seq(0, 2*pi, length=21)[-21] x - cos(angle) y - sin(angle) xyplot( y ~ x, aspect = 1) Lets say I take the pointsGrob below: getNames() [1] GRID.rect.748 plot1.xlabplot1.ylab GRID.segments.749 [5] GRID.segments.750 GRID.text.751 GRID.segments.752 GRID.text.753 [9] GRID.segments.754 GRID.points.755 GRID.rect.756 pg = grid.get(GRID.points, grep=TRUE) pg points[GRID.points.755] Is there a way I can add a point to pg (or GRID.points.755) to update the xyplot without redrawing all the points ? If redrawing is obligatory, is there way of redrawing the least elements of the xyplot ? Searched for a long time but could not find anything, even if this seems like a fairly basic operation. I guess this may well go against the grid's package philosophy or architecture ? Thanks. Daniel. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/Can-I-add-a-point-to-a-pointsGrob-from-an-xyplot-without-redrawing---tp21579096p21579234.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using time series
Hello, I'm trying to analyze the behavior of a series of numbers. Let's say I have the following data: 0 0 0 20 20 20 50 50 53 56 23 24 21 10 0 4 129 159 30 0 0 0 (for example) - these numbers are some measurements that are taken on equal interval of times (but the specific moment in time (e.g. spring or march) is not relevant - just equal intervals of time). What I want to do is based on the past data to be able to predict what will happen next. I've been advised to use time series, but I have no idea how to do that in R. Can someone suggest a better method than time series and if not - can you pls suggest some sample R code for predicting using time series? Thanks! Best, Jana [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using time series
Try: library(forecast) plot(forecast(auto.arima(x))) On Wed, Jan 21, 2009 at 4:01 AM, Yana Mileva yanamil...@googlemail.com wrote: Hello, I'm trying to analyze the behavior of a series of numbers. Let's say I have the following data: 0 0 0 20 20 20 50 50 53 56 23 24 21 10 0 4 129 159 30 0 0 0 (for example) - these numbers are some measurements that are taken on equal interval of times (but the specific moment in time (e.g. spring or march) is not relevant - just equal intervals of time). What I want to do is based on the past data to be able to predict what will happen next. I've been advised to use time series, but I have no idea how to do that in R. Can someone suggest a better method than time series and if not - can you pls suggest some sample R code for predicting using time series? Thanks! Best, Jana [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Vector Autocorrelation Function in R?
Hello. Does anyone know, if there is a function in R to compute the vector autocorrelations? Thank you in advance. Regards, Andreas. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Looking for a special date function in R
Hello, everyone I wonder if R has something similar to Excel function EDATE(start_date; months) which returns a serial number of the date that is the indicated number of months before of after the start date. Example (the second column EDATE(first_column; -6)): 01.01.1999 01.07.1998 02.02.1999 02.08.1998 06.03.1999 06.09.1998 I am working with a zoo object where the row names are dates and for particular rows I need to find values that were recorded 6 months before (or return NA if the date is before the timeseries start). Maybe someone knows a passable R function for that kind of operation? Thanks in advance for help! Best, Sergey __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking for a special date function in R
See ?julian julian(Sys.Date(), Sys.Date() - 10) # 10 [1] 10 attr(,origin) [1] 2009-01-11 and R News 4/1. On Wed, Jan 21, 2009 at 4:37 AM, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone I wonder if R has something similar to Excel function EDATE(start_date; months) which returns a serial number of the date that is the indicated number of months before of after the start date. Example (the second column EDATE(first_column; -6)): 01.01.1999 01.07.1998 02.02.1999 02.08.1998 06.03.1999 06.09.1998 I am working with a zoo object where the row names are dates and for particular rows I need to find values that were recorded 6 months before (or return NA if the date is before the timeseries start). Maybe someone knows a passable R function for that kind of operation? Thanks in advance for help! Best, Sergey __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Text Outside Lattice Plot
I created the graph at the bottom using xyplot in the lattice package. I added a title using the main=Title command in xyplot, however it is plotted too close to the legend for my liking. To remedy this I increased the upper margin of the plot using plot(data, position = c(0,0,1,.9)) and attempted to move SNA upwards and to the right. I have tried using a variety of text functions such as: trellis.focus(panel, 1, 1) panel.text(x=11, y=10, labels=SNA) trellis.unfocus() panel.xyplot(...) panel.text(x=11, y=10, labels=SNA) library(grid) ltext(grid.locator(), label='SNA') The first two of these functions work but the text disappears once I specify a y coordinate ymax. The last function appears to work but requires me to click on the plot to specify the location (I need this to be pre-defined). Does anyone know how I can do this? A simple way to get more space for the title is to change the layout height parameter. Here's an adaptation of the OrchardSprays example in ?xyplot. xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos, type = a, auto.key = list(space = top, points = FALSE, lines = TRUE), main=Orchard sprays example, par.settings=list(layout.heights=list(main=4))) Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: problem with rbind
Hi data-read.table(data.txt, header=T, sep='\t') Error in file(file, r) : cannot open the connection In addition: Warning message: In file(file, r) : cannot open file 'data.txt': No such file or directory gives me an error so it is not possible to reproduce your function. However it looks like work for lapply, sapply, by or similar see e.g. lapply(split(iris[,1:4], iris$Species), function(x) cbind(mean(x), sd(x))) by(iris[,1:4], iris$Species, function(x) cbind(mean(x), sd(x))) Regards Petr r-help-boun...@r-project.org napsal dne 21.01.2009 06:07:40: Hi All, I have a problem with rbind. I have data that consist of weight height .. etc of 1000 patients. I would like to find the mean and the standard deviation ( for the weight , height etc) for each gender. data-read.table(data.txt, header=T, sep='\t') fdata=NULL for (i in 1:50){ nn-names(X)[i] m-tapply(X[,i],data$gender,mean,na.rm=T) s-tapply(X[,i], data$gender, sd,na.rm=T) p-cbind(mean=m,sd.dev=s) cn-paste(nn,colnames(p),sep=_) colnames(p)-cn fdata-rbind(fdata,p) } write.table(fdata, “results.txt”,sep=’\t’,quote=FALSE, col.names=T) here is the problem, 1. I have a header for each table but only the first one is printed. 2. the weight_mean is suppose to be on the top of the means but it appears on the top of the first column ( with no tab before the header) weight_meanweight_sd.dev F 14.3 4.932883 M 34.7 10.692677 F 35.0 7.071068 M 34.7 10.692677 . . . I want the result to look like this with a line separating each table and each table has a header weight_meanweight_sd.dev F 14.3 4.932883 M 34.7 10.692677 hight_meanhight_sd.dev F 35.0 7.071068 M 34.7 10.692677 3.Is there a way to make a title for each table, for example weight weight_meanweight_sd.dev F 14.3 4.932883 M 34.7 10.692677 I appreciate your help, -- View this message in context: http://www.nabble.com/problem-with-rbind- tp21577241p21577241.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: problem with writing data to *.xls file
Hi It depends if you have Excel available write.excel-function(tab, ...) write.table( tab, clipboard, sep=\t, row.names=F) this function I use for copying object through clipboard to opened Excel file. just write.excel(someobject) open excel list Ctrl-V puts an object into a list. Regards Petr r-help-boun...@r-project.org napsal dne 20.01.2009 15:18:00: Hi all, I read data from *.xls file and i did some caliculations on that data and now i have to create a column in the same .xls file and i have to insert the data in to the consicutive rows related to the previous data i tried it with *write.xls() *but the thing is it deleted all the columns previously presented in that file and it created a column and inserted data can any one suggest what to do for this thanks in advance [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R and Xcode Editor
Hi From the R for OS X FAQ page: (http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html ) 4.4.6 Editor (internal and external): Using AppleScript it is easy to implement Command-E and Command-Return like functionality. How? Regards, Gregor. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Function able to identify the row and the column in a matrix
Good morning to all, I should evaluate a function for every cell of a given matrix with n rows and n columns. This function, named fun(), has got two arguments: the number of the row and the number of the column which characterized every single cell. So the result should be fun(1,1) fun(1,2) ... fun(1,n) fun(2,1) fun(2,2) ... fun(2,n) ......... ... fun(n,1) fun(n,2) ... fun(n,n) Does it exist a function which could build this new matrix, where each element in the cell (i,j) is fun(i,j), with 1=i, j=n? Thank you very much, Enrico Foscolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: Function able to identify the row and the column in a matrix
Hi ?outer regards Petr r-help-boun...@r-project.org napsal dne 21.01.2009 11:47:03: Good morning to all, I should evaluate a function for every cell of a given matrix with n rows and n columns. This function, named fun(), has got two arguments: the number of the row and the number of the column which characterized every single cell. So the result should be fun(1,1) fun(1,2) ... fun(1,n) fun(2,1) fun(2,2) ... fun(2,n) ......... ... fun(n,1) fun(n,2) ... fun(n,n) Does it exist a function which could build this new matrix, where each element in the cell (i,j) is fun(i,j), with 1=i, j=n? Thank you very much, Enrico Foscolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Predictions with GAM
Here's a simulated example (although really for this model structure, one might as well fit seperate models for each factor level). ## Simulate some data with factor dependent smooths n - 400 x - runif(n, 0, 1) f1 - 2 * sin(pi * x) f2 - exp(2 * x) - 3.75887 f3 - 0.2 * x^11 * (10 * (1 - x))^6 + 10 * (10 * x)^3 * (1 - x)^10 fac - as.factor(c(rep(1, 100), rep(2, 100), rep(3, 200))) fac.1 - as.numeric(fac == 1) fac.2 - as.numeric(fac == 2) fac.3 - as.numeric(fac == 3) f - f1 * fac.1 + f2 * fac.2 + f3 * fac.3 y - rpois(f,exp(f/4)) ## fit gam, with a smooth of `x' for each level of `fac' b - gam(y~s(x,by=fac)+fac,family=poisson) par(mfrow=c(2,2)) plot(b) ## produce plots on response scale, first the prediction... np - 200 newd - data.frame(x=rep(seq(0,1,length=np),3), fac=factor(c(rep(1,np),rep(2,np),rep(3,np pv - predict(b,newd,type=response) ## .. now the plotting par(mfrow=c(2,2)) ind - 1:np plot(newd$x[ind],pv[ind],type=l,xlab=x,ylab=f(x,fac=1)) ind - ind+np plot(newd$x[ind],pv[ind],type=l,xlab=x,ylab=f(x,fac=2)) ind - ind+np plot(newd$x[ind],pv[ind],type=l,xlab=x,ylab=f(x,fac=2)) On Friday 16 January 2009 14:30, Robbert Langenberg wrote: Thanks for the swift reply, I might have been a bit sloppy with describing my datasets and problem. I showed the first model as an example of the type of GAM that I had been able to use the predict function on. What I am looking for is how to predict my m3: model3-gam(y_no~s(day,by=mapID),family=binomial, data=mergeday) When I plot this I get 8 different graphs. Each showing me a different habitat type with on the x-axis days and on the y-axis s(day,2,81):mapID. With predict I was hoping to get the scale of the y-axis right for a selection of days (for example 244,304). I have tried to reform the script you gave me to match my dataset in m3, but it all did not seem to work. newd2 - data.frame(day = rep(seq(244, 304, length = 100), 8), mapID = rep(levels(mergeday$mapID), each = 100)) newd2 - data.frame(day = rep(seq(244, 304, length = 100), 8), mapID = rep(sort(unique(mergeday$mapID)), each = 100)) I am guessing it must have something to do with the by in s(day,by=mapID). I haven't come across any examples that used a GAM with by and then used the predict function. (A sample of the dataset: mapID day y_no Urban Areas and Water25 1 Urban Areas and Water26 1 Early Succesional Forest 27 0 Agriculture 28 0 Early Succesional Forest 29 0 Mature Coniferous Forest 30 0) I am sorry that I have to bother you even more with this, and I hope that my additional explanation about my problem might help solve it. Sincerely yours, Robbert Langenberg 2009/1/16 Gavin Simpson gavin.simp...@ucl.ac.uk On Fri, 2009-01-16 at 12:36 +0100, Robbert Langenberg wrote: Dear, I am trying to get a prediction of my GAM on a response type. So that I eventually get plots with the correct values on my ylab. I have been able to get some of my GAM's working with the example shown below: * model1-gam(nsdall ~ s(jdaylitr2), data=datansd) newd1 - data.frame(jdaylitr2=(244:304)) pred1 - predict.gam(model1,newd1,type=response)* Hi Robert, You want predictions for the covariate over range 244:304 for each of your 8 mapID's, yes? This is not tested, but why not something like: newd2 - data.frame(jdaylitr2 = rep(seq(244, 304, length = 100), 8), mapID = rep(levels(datansd$mapID), each = 100)) Then use newd2 in your call to predict. I am assuming that datansd$mapID is a factor in the above. If it is just some other indicator variable, then perhaps something like: newd2 - data.frame(jdaylitr2 = rep(seq(244, 304, length = 100), 8), mapID = rep(sort(unique(datansd$mapID)), each = 100)) Does that work for you? HTH G The problem I am encountering now is that I cannot seem to get it done for the following type of model: *model3-gam(y_no~s(day,by=mapID),family=binomial, data=mergeday)* My mapID consists of 8 levels of which I get individual plots with * plot(model3)*. When I do predict with a newdata in it just like my first model I need all columns to have the same amount of rows or else R will not except it ofcourse, the col.names need to at least include day and mapID. This way I can not get a prediction working for this GAM, I am confused because of this part in the model: *s(day,by=mapID). *I have been reading through the GAM, an introduction with R book from Wood, S. but could not find anything about predictions with BY in the model. I hope someone can help me out with this, Sincerely yours, Robbert Langenberg [[alternative HTML
[R] Function able to identify the row and the column in a matrix
Good morning to all, I should evaluate a function for every cell of a given matrix with n rows and n columns. This function, named fun(), has got two arguments: the number of the row and the number of the column which characterized every single cell. So the result should be fun(1,1) fun(1,2) ... fun(1,n) fun(2,1) fun(2,2) ... fun(2,n) ......... ... fun(n,1) fun(n,2) ... fun(n,n) Does it exist a function which could build this new matrix, where each element in the cell (i,j) is fun(i,j), with 1=i, j=n? Thank you very much, Enrico Foscolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking for a special date function in R
Dear Gabor, Thanks for that! Still, it is not really similar to how EDATE works. With julian(Sys.Date(), Sys.Date() - 10) one moves 10 days back. The problem is that I need to move by months, not by days, as months have different number of days. I need to come to the same day when I move backward or forward in time, for example going back one month from today (21.01.2009) I need to come to 21.12.2008. I've read through your article in RNews 4/1 but still do not know how to do what I need to do. Regards, Sergey On Wed, Jan 21, 2009 at 10:44, Gabor Grothendieck ggrothendi...@gmail.com wrote: See ?julian julian(Sys.Date(), Sys.Date() - 10) # 10 [1] 10 attr(,origin) [1] 2009-01-11 and R News 4/1. On Wed, Jan 21, 2009 at 4:37 AM, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone I wonder if R has something similar to Excel function EDATE(start_date; months) which returns a serial number of the date that is the indicated number of months before of after the start date. Example (the second column EDATE(first_column; -6)): 01.01.1999 01.07.1998 02.02.1999 02.08.1998 06.03.1999 06.09.1998 I am working with a zoo object where the row names are dates and for particular rows I need to find values that were recorded 6 months before (or return NA if the date is before the timeseries start). Maybe someone knows a passable R function for that kind of operation? Thanks in advance for help! Best, Sergey __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with cyrillic in postscript
1) Please update your R as requested in the posting guide, and provide the 'at a mimimum' information requested. 2) Try reading ?postscript and setting the encoding: I suspect yours is not one of the cases that are guessed correctly. 3) If all else fails, give a 'commented, minimal, self-contained, reproducible' example. You will need to be careful with encodings, so it would be best to put it on a website and tell us the file encoding. On Wed, 21 Jan 2009, Alexander Nakhabov wrote: Hi all, When I plot some graph with cyrillic (namely russian) titles it looks ok, but after saving this figure as eps file I get damaged title fonts. The command dev.copy2eps was used in the following manner: dev.copy2eps(test.eps) or, for example dev.copy2eps(test.eps,family='NimbusSan') What is wrong? I use R 2.6.0 under Windows. Any help will be appreciated. Regards, Alexander Nakhabov [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help Regarding STL Technique
Team, I have a time series data with lot of seasonality and trends. I am familiar with some forecasting techniques, but for this set, I believe STL would be the best. Please let me know any tips to use STL using R. Best, Kishore [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking for a special date function in R
On Wed, 21 Jan 2009, Sergey Goriatchev wrote: Dear Gabor, Thanks for that! Still, it is not really similar to how EDATE works. With julian(Sys.Date(), Sys.Date() - 10) one moves 10 days back. The problem is that I need to move by months, not by days, as months have different number of days. I need to come to the same day when I move backward or forward in time, for example going back one month from today (21.01.2009) I need to come to 21.12.2008. I've read through your article in RNews 4/1 but still do not know how to do what I need to do. The trick is to use the POSIXlt class. E.g. x - Sys.Date() xx - as.POSIXlt(x) xx$mon - xx$mon - 6 as.Date(xx) [1] 2008-07-21 Now, the issue is what date is 6 months before 2008-08-31, and I'll leave you to ponder what that means. Regards, Sergey On Wed, Jan 21, 2009 at 10:44, Gabor Grothendieck ggrothendi...@gmail.com wrote: See ?julian julian(Sys.Date(), Sys.Date() - 10) # 10 [1] 10 attr(,origin) [1] 2009-01-11 and R News 4/1. On Wed, Jan 21, 2009 at 4:37 AM, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone I wonder if R has something similar to Excel function EDATE(start_date; months) which returns a serial number of the date that is the indicated number of months before of after the start date. Example (the second column EDATE(first_column; -6)): 01.01.1999 01.07.1998 02.02.1999 02.08.1998 06.03.1999 06.09.1998 I am working with a zoo object where the row names are dates and for particular rows I need to find values that were recorded 6 months before (or return NA if the date is before the timeseries start). Maybe someone knows a passable R function for that kind of operation? Thanks in advance for help! Best, Sergey __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Odp: R: Odp: Function able to identify the row and the column in a matrix
enrico.fosco...@libero.it enrico.fosco...@libero.it napsal dne 21.01.2009 11:54:49: I can't use the function outer because my function fun() doesn't take vectors as arguments. If you can not R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. you probably can not expect reasonable answer to such vague question Regards Petr Thank You, Enrico Foscolo Messaggio originale Da: petr.pi...@precheza.cz Data: 21-gen-2009 11.52 A: enrico.fosco...@libero.it enrico.fosco...@libero.it Cc: r-help@r-project.org Ogg: Odp: [R] Function able to identify the row and the column in a matrix Hi ?outer regards Petr r-help-boun...@r-project.org napsal dne 21.01.2009 11:47:03: Good morning to all, I should evaluate a function for every cell of a given matrix with n rows and n columns. This function, named fun(), has got two arguments: the number of the row and the number of the column which characterized every single cell. So the result should be fun (1,1) fun(1,2) ... fun(1,n) fun(2,1) fun(2,2) ... fun(2,n) ......... ... fun(n,1) fun(n,2) ... fun(n,n) Does it exist a function which could build this new matrix, where each element in the cell (i,j) is fun(i,j), with 1=i, j=n? Thank you very much, Enrico Foscolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking for a special date function in R
Dear Prof. Ripley, Thank you for help. Yes, that is an interesting question you pose. I already thought myself how February should be handled, as EDATE(31.08.2008; -6) returns 29.02.2008. In Excel it is not a problem, since this nonexisting date is then used in VLOOKUP function where one can have Range.Lookup argument set to TRUE and then it finds the closest value. Example from Excel (value for 29.02.2008 is recovered from the sorted table with VLOOKUP function): 21.07.2008 10.00 31.08.2008 20.00 28.02.2008 30.00 01.03.2008 40.00 02.03.2008 50.00 03.03.2008 60.00 29.02.2008 30 I wonder if that kind of functionality is available in R, or one has to write a piece of code oneself to acheive it. Thank you for your time and help! Regards, Sergey On Wed, Jan 21, 2009 at 12:44, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: On Wed, 21 Jan 2009, Sergey Goriatchev wrote: Dear Gabor, Thanks for that! Still, it is not really similar to how EDATE works. With julian(Sys.Date(), Sys.Date() - 10) one moves 10 days back. The problem is that I need to move by months, not by days, as months have different number of days. I need to come to the same day when I move backward or forward in time, for example going back one month from today (21.01.2009) I need to come to 21.12.2008. I've read through your article in RNews 4/1 but still do not know how to do what I need to do. The trick is to use the POSIXlt class. E.g. x - Sys.Date() xx - as.POSIXlt(x) xx$mon - xx$mon - 6 as.Date(xx) [1] 2008-07-21 Now, the issue is what date is 6 months before 2008-08-31, and I'll leave you to ponder what that means. Regards, Sergey On Wed, Jan 21, 2009 at 10:44, Gabor Grothendieck ggrothendi...@gmail.com wrote: See ?julian julian(Sys.Date(), Sys.Date() - 10) # 10 [1] 10 attr(,origin) [1] 2009-01-11 and R News 4/1. On Wed, Jan 21, 2009 at 4:37 AM, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone I wonder if R has something similar to Excel function EDATE(start_date; months) which returns a serial number of the date that is the indicated number of months before of after the start date. Example (the second column EDATE(first_column; -6)): 01.01.1999 01.07.1998 02.02.1999 02.08.1998 06.03.1999 06.09.1998 I am working with a zoo object where the row names are dates and for particular rows I need to find values that were recorded 6 months before (or return NA if the date is before the timeseries start). Maybe someone knows a passable R function for that kind of operation? Thanks in advance for help! Best, Sergey __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk 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 -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking for a special date function in R
On Wed, 21 Jan 2009, Sergey Goriatchev wrote: Dear Prof. Ripley, Thank you for help. Yes, that is an interesting question you pose. I already thought myself how February should be handled, as EDATE(31.08.2008; -6) returns 29.02.2008. In Excel it is not a problem, since this nonexisting date is then used in VLOOKUP function where one can have Range.Lookup argument set to TRUE and then it finds the closest value. Example from Excel (value for 29.02.2008 is recovered from the sorted table with VLOOKUP function): 21.07.2008 10.00 31.08.2008 20.00 28.02.2008 30.00 01.03.2008 40.00 02.03.2008 50.00 03.03.2008 60.00 29.02.2008 30 I wonder if that kind of functionality is available in R, or one has to write a piece of code oneself to acheive it. Easy to do in the same way as I showed you. Thank you for your time and help! Regards, Sergey On Wed, Jan 21, 2009 at 12:44, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: On Wed, 21 Jan 2009, Sergey Goriatchev wrote: Dear Gabor, Thanks for that! Still, it is not really similar to how EDATE works. With julian(Sys.Date(), Sys.Date() - 10) one moves 10 days back. The problem is that I need to move by months, not by days, as months have different number of days. I need to come to the same day when I move backward or forward in time, for example going back one month from today (21.01.2009) I need to come to 21.12.2008. I've read through your article in RNews 4/1 but still do not know how to do what I need to do. The trick is to use the POSIXlt class. E.g. x - Sys.Date() xx - as.POSIXlt(x) xx$mon - xx$mon - 6 as.Date(xx) [1] 2008-07-21 Now, the issue is what date is 6 months before 2008-08-31, and I'll leave you to ponder what that means. Regards, Sergey On Wed, Jan 21, 2009 at 10:44, Gabor Grothendieck ggrothendi...@gmail.com wrote: See ?julian julian(Sys.Date(), Sys.Date() - 10) # 10 [1] 10 attr(,origin) [1] 2009-01-11 and R News 4/1. On Wed, Jan 21, 2009 at 4:37 AM, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone I wonder if R has something similar to Excel function EDATE(start_date; months) which returns a serial number of the date that is the indicated number of months before of after the start date. Example (the second column EDATE(first_column; -6)): 01.01.1999 01.07.1998 02.02.1999 02.08.1998 06.03.1999 06.09.1998 I am working with a zoo object where the row names are dates and for particular rows I need to find values that were recorded 6 months before (or return NA if the date is before the timeseries start). Maybe someone knows a passable R function for that kind of operation? Thanks in advance for help! Best, Sergey __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk 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 -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Handling of factors
Thomas Lumley wrote: On Tue, 20 Jan 2009, Stavros Macrakis wrote: I'm rather confused by the semantics of factors. snip actual confusion It is all very confusing. Of course, most of this behavior is documented and is easily determined by experimentation, but it would be easier to learn and teach the language if there were some clear principle underlying all this. What am I missing? No, it really is confusing. The problem is that there are two conflicting clear principles. Factors could be - integer variables with labels (similar to value labels in Stata/SPSS or C enums) - variables that takes on values from a pre-specified set, implemented using integer codes (like Pascal enumerated types). It might be worth noting here that in the second variation, the set will have to be ordered for pragmatic reasons (order of entries in tables, contrast matrices, etc.) even for non-ordered factors. So you can always _define_ the integer codes. In that light, you could say that it is only a matter of making the conventions consistent as to whether factors are character-like or integer-like. [In fact, there was historically even a third way to view factors, as way to reduce the memory use of string variables. That's obsolete now.] That is, the fact that they are small integers can be seen as part of the interface or just as part of the implementation. It's obvious which one is right, but unfortunately it is differently obvious to different people. AFAIK there has never been a unified policy on this, dating back before R, so different functions behave differently. There have been changes in R over the years, mostly in the direction of making factors more like Pascal enumerations. S3-style object-orientation and coercion rules also played their part: It was easy to code a group method for == so that sex==male works and sex==1 does not (unless levels(sex) include 1), but in the [ operator we have automatic unclass() of the index (with S3, you can dispatch on what class of object you index, but not what you index with), so that plot(x,y, col=c(male=lightblue, female=pink)[sex]) will _not_ do character indexing, and may well give the opposite result of what it looks like. We could change the convention here (coerce factor to character), but there are a couple of demons: What if the object you are indexing does not have names or has incompatible names, and would there not be a performance hit? Also, the law of inertia: The existing conventions have been used for quite a while, so changing them could break code in unexpected places. Notice, by the way, that in comparison operations between (ordered) factor and character, it is the character that is coerced to a factor, not the other way around: cooked = medium should include rare... -- 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 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking for a special date function in R
This will give you 6 months after today. Use negative numbers to move backwards: d - Sys.Date() seq(d, length = 2, by = paste(6, months))[2] [1] 2009-07-21 On Wed, Jan 21, 2009 at 6:27 AM, Sergey Goriatchev serg...@gmail.com wrote: Dear Gabor, Thanks for that! Still, it is not really similar to how EDATE works. With julian(Sys.Date(), Sys.Date() - 10) one moves 10 days back. The problem is that I need to move by months, not by days, as months have different number of days. I need to come to the same day when I move backward or forward in time, for example going back one month from today (21.01.2009) I need to come to 21.12.2008. I've read through your article in RNews 4/1 but still do not know how to do what I need to do. Regards, Sergey On Wed, Jan 21, 2009 at 10:44, Gabor Grothendieck ggrothendi...@gmail.com wrote: See ?julian julian(Sys.Date(), Sys.Date() - 10) # 10 [1] 10 attr(,origin) [1] 2009-01-11 and R News 4/1. On Wed, Jan 21, 2009 at 4:37 AM, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone I wonder if R has something similar to Excel function EDATE(start_date; months) which returns a serial number of the date that is the indicated number of months before of after the start date. Example (the second column EDATE(first_column; -6)): 01.01.1999 01.07.1998 02.02.1999 02.08.1998 06.03.1999 06.09.1998 I am working with a zoo object where the row names are dates and for particular rows I need to find values that were recorded 6 months before (or return NA if the date is before the timeseries start). Maybe someone knows a passable R function for that kind of operation? Thanks in advance for help! Best, Sergey __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] A question on histogram (hist): coordinates on x-axis are too sparse
Li, Hua wrote: Dear R helpers: Let's say I have some data X, X - runif(1000, 1, 100) pdf('X.pdf', width=100,height=5) hist(X, breaks=1000) dev.off() I find that, on x-axis the coordinates are 0e+00, 2e+09, 4e+09, 6e+09, 8e+09, 1e+10. Only five numbers, which is too sparse in a 100x5 pdf file. I want the x-axis coordinates to become more dense, e.g. 0e+00, 1e+09, 2e+09, 3e+09,. 8e+09, 9e+09, 1e+10. What argument (or function) should I revise to let this happen?? Thanks a lot!! Best, Hua You can draw the axes yourself: hist(X, axes=F) axis(1, at=pretty(X, n=100)) axis(2) box() Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging several dataframes from a list
Try this also: cbind(pos = mylist$df1$pos, data.frame(mylist)[grep(data, names(data.frame(mylist)))]) On Wed, Jan 21, 2009 at 6:19 AM, Antje niederlein-rs...@yahoo.de wrote: Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave: conflict between setwd and \SweaveOpts{prefix.string=}
Have you tried specifying an absolute path in prefix.string instead of a relative one? HTH, Thierry Good point! This actually solves the problem, I just wanted to avoid this as I wanted to send it to someone else... so I just reordered the files and it works. Solutions given by Duncan work also, nice! I agree with you Duncan, it is not a big problem, and doesn't need at all priority, but mentioning it is maybe worth in the doc, especially if this could avoid someone to lose those two hours I lost with this Thanks to all you both! Duncan Murdoch a écrit : Matthieu Stigler wrote: Hello I think there is a conflict between setwd() and \SweaveOpts{prefix.string=}. In the same document, those both command get Sweave confuse the files and directories. See: say my .Rnw document is in File1 If one inserts some setwd() for another file: -setwd(File2) then the command \SweaveOpts{prefix.string=graphics/Rplots} will search the graphics folder in File2 because of command setwd(File2) and not in File1 where the .Rnw file is and as is said in Sweave Manual A10. Hence Latex get really confused and does not work anymore: the command \includegraphics looks for folder graphics in the usual File1 but those can have been stored in File2. I tried to add some: \usepackage{graphicx} \graphicspath{{../File2/graphics/}} but resulot was not so convincing Is there anyway to avoid this? Thanks! You could use a fully qualified prefix, so it doesn't matter what the current directory is when you save a plot. Or you could avoid setwd(). Or you could change back to the original directory before drawing a plot. It would probably make sense for Sweave to do the last of these internally: it is mixing up characteristics of the session it's running in with characteristics of the session it is running. However, this is a pretty strange case, and I'm not sure fixing it will be a high priority. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging several dataframes from a list
Henrique Dallazuanna schrieb: Try this also: cbind(pos = mylist$df1$pos, data.frame(mylist)[grep(data, names(data.frame(mylist)))]) Hi Henrique, cool solution - that's seems to be the easiest way! though I thought there should be some possibiliy of multiple merge Anyway, this will do it for now! Thank you! On Wed, Jan 21, 2009 at 6:19 AM, Antje niederlein-rs...@yahoo.de mailto:niederlein-rs...@yahoo.de wrote: Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging several dataframes from a list
Hi Antje, Try this: merge(merge(mylist[[1]], mylist[[2]], by = pos), mylist[[3]]) On Wed, Jan 21, 2009 at 11:19 AM, Antje niederlein-rs...@yahoo.de wrote: Henrique Dallazuanna schrieb: Try this also: cbind(pos = mylist$df1$pos, data.frame(mylist)[grep(data, names(data.frame(mylist)))]) Hi Henrique, cool solution - that's seems to be the easiest way! though I thought there should be some possibiliy of multiple merge Anyway, this will do it for now! Thank you! On Wed, Jan 21, 2009 at 6:19 AM, Antje niederlein-rs...@yahoo.demailto: niederlein-rs...@yahoo.de wrote: Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging several dataframes from a list
merge.zoo can do a multiple merge. We create a list of zoo objects, mylist.z, and then perform the merge: library(zoo) mylist.z - lapply(mylist, function(x) zoo(x$data, as.character(x$pos))) do.call(merge.zoo, mylist.z) df1 df2 df3 A 2 6 9 B 6 2 3 C 3 9 6 D 1 7 2 E 9 5 1 On Wed, Jan 21, 2009 at 8:19 AM, Antje niederlein-rs...@yahoo.de wrote: Henrique Dallazuanna schrieb: Try this also: cbind(pos = mylist$df1$pos, data.frame(mylist)[grep(data, names(data.frame(mylist)))]) Hi Henrique, cool solution - that's seems to be the easiest way! though I thought there should be some possibiliy of multiple merge Anyway, this will do it for now! Thank you! On Wed, Jan 21, 2009 at 6:19 AM, Antje niederlein-rs...@yahoo.de mailto:niederlein-rs...@yahoo.de wrote: Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Looking for a special date function in R
Thank you all for your help! Sergey On Wed, Jan 21, 2009 at 13:25, Gabor Grothendieck ggrothendi...@gmail.com wrote: This will give you 6 months after today. Use negative numbers to move backwards: d - Sys.Date() seq(d, length = 2, by = paste(6, months))[2] [1] 2009-07-21 On Wed, Jan 21, 2009 at 6:27 AM, Sergey Goriatchev serg...@gmail.com wrote: Dear Gabor, Thanks for that! Still, it is not really similar to how EDATE works. With julian(Sys.Date(), Sys.Date() - 10) one moves 10 days back. The problem is that I need to move by months, not by days, as months have different number of days. I need to come to the same day when I move backward or forward in time, for example going back one month from today (21.01.2009) I need to come to 21.12.2008. I've read through your article in RNews 4/1 but still do not know how to do what I need to do. Regards, Sergey On Wed, Jan 21, 2009 at 10:44, Gabor Grothendieck ggrothendi...@gmail.com wrote: See ?julian julian(Sys.Date(), Sys.Date() - 10) # 10 [1] 10 attr(,origin) [1] 2009-01-11 and R News 4/1. On Wed, Jan 21, 2009 at 4:37 AM, Sergey Goriatchev serg...@gmail.com wrote: Hello, everyone I wonder if R has something similar to Excel function EDATE(start_date; months) which returns a serial number of the date that is the indicated number of months before of after the start date. Example (the second column EDATE(first_column; -6)): 01.01.1999 01.07.1998 02.02.1999 02.08.1998 06.03.1999 06.09.1998 I am working with a zoo object where the row names are dates and for particular rows I need to find values that were recorded 6 months before (or return NA if the date is before the timeseries start). Maybe someone knows a passable R function for that kind of operation? Thanks in advance for help! Best, Sergey __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] matching more than two vectors (?)- Resolved
Dear Juliet, I found out that the issue of matching more than two vectors can be avoided by pasting vectors into one using paste(). Also, it is not actually necessary for my problem to use match(). I was looking for a method to match points by coordinates, this can be done be using equal coordinates in an index. I this worked for me: 1. paste() puts both x and y coordinate into one column: Examples: Dist_shoreDF$coord=paste(Dist_shoreDF$UTMX,Dist_shoreDF$UTMY,sep=,) fishmove$coord[day=i+1]=paste(fishmove$UTMX[day=i+1],fishmove$UTMY[day=i+1],sep=,) 2. Equal coordinates can be used as an index to match two points: Example: fishlocationDF$distance[day=i+1]=Dist_shoreDF$distance[Dist_shoreDF$coord==fishmove$coord[day=i+1]] reads the required distance from Dist_shoreDF into fishlocationDF for corresponding points. (This the bit that I was really looking for !). Thank you for your time. Regards, Juliane Dr. Juliane Struve Environmental Scientist 10, Lynwood Crescent Sunningdale SL5 0BL 01344 620811 - Original Message From: Juliet Hannah juliet.han...@gmail.com To: Juliane Struve juliane_str...@yahoo.co.uk Sent: Tuesday, 20 January, 2009 3:30:16 Subject: Re: [R] matching more than two vectors (?) Could you create a small example of inputs and the desired output? On Fri, Jan 16, 2009 at 3:57 PM, Juliane Struve juliane_str...@yahoo.co.uk wrote: Dear listmembers, I am trying to obtain values for pointdistance from another dataframe by matching UTMX and UTMY coordinates, but I am not sure how to introduce the second coordinate. PointDF$pointdistance=DistanceDF$distance[match(PointDF$UTMX,DistanceDF$UTMX PointDF$UTMY,DistanceDF$UTMY )] is wrong but (hopefully) illustrates what I am trying to do. Could somebody help ? Thank you very much. Juliane __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] obtaining null components of a list
Hello everybody! I have a list of length 5000 whose components are (mostly) ts objects, but some these components are intentionally left empty, ie, they are NULL components of the list. My question is how can I get the position of these null components in a effective way (I'm trying to avoid a for-if rutine). Thanks!!! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Two similar zoo objects with different structures, how to get same structure?
Dear all, I have a zoo object that has following structure: str(bldata) zoo [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, index)=Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... .. ..- attr(*, format)= chr m/d/y .. ..- attr(*, origin)= Named num [1:3] 1 1 1970 .. .. ..- attr(*, names)= chr [1:3] month day year - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... I also have a vector of dates of same length as zoo object (5219): str(bldates) chr [1:5219] 01/01/90 01/02/90 01/03/90 01/04/90 01/05/90 01/08/90 01/09/90 01/10/90 01/11/90 01/12/90 ... I do the following: attributes(bldata)[[2]] - as.Date(bldates, %m/%d/%y) and get the following: str(bldata) 'zoo' series from 1990-01-01 to 2009-12-31 Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... Index: Class 'Date' num [1:5219] 7305 7306 7307 7308 7309 ... But what I really want to get is the following: str(bldata) 'zoo' series from 01/01/90 to 12/31/09 Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... Index: Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... ..- attr(*, format)= chr m/d/y ..- attr(*, origin)= Named num [1:3] 1 1 1970 .. ..- attr(*, names)= chr [1:3] month day year The array bldata is the same, only the last one is on a machine running RBloomberg, and then I tried to save bldata (and rownames of bldata in bldates) and transfer bldata to the other machine which is not a Bloomberg terminal, and the structure of bldata changes. What should I do in this case to adjust the structure? I guess I have to somehow change the class of Index and set attributes of Index and attribute names of attribute origin of attribute Index? Thank you for your help in advance! Regards, Sergey -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] obtaining null components of a list
Try this: x - list(NULL, 1:10, 25, NULL, more) x [[1]] NULL [[2]] [1] 1 2 3 4 5 6 7 8 9 10 [[3]] [1] 25 [[4]] NULL [[5]] [1] more which(sapply(x, is.null)) [1] 1 4 On Wed, Jan 21, 2009 at 7:42 AM, diego Diego dhab...@gmail.com wrote: Hello everybody! I have a list of length 5000 whose components are (mostly) ts objects, but some these components are intentionally left empty, ie, they are NULL components of the list. My question is how can I get the position of these null components in a effective way (I'm trying to avoid a for-if rutine). Thanks!!! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two similar zoo objects with different structures, how to get same structure?
Please reduce your examples down to small amounts of data and use dput so that they are reproducible. On Wed, Jan 21, 2009 at 9:32 AM, Sergey Goriatchev serg...@gmail.com wrote: Dear all, I have a zoo object that has following structure: str(bldata) zoo [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, index)=Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... .. ..- attr(*, format)= chr m/d/y .. ..- attr(*, origin)= Named num [1:3] 1 1 1970 .. .. ..- attr(*, names)= chr [1:3] month day year - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... I also have a vector of dates of same length as zoo object (5219): str(bldates) chr [1:5219] 01/01/90 01/02/90 01/03/90 01/04/90 01/05/90 01/08/90 01/09/90 01/10/90 01/11/90 01/12/90 ... I do the following: attributes(bldata)[[2]] - as.Date(bldates, %m/%d/%y) and get the following: str(bldata) 'zoo' series from 1990-01-01 to 2009-12-31 Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... Index: Class 'Date' num [1:5219] 7305 7306 7307 7308 7309 ... But what I really want to get is the following: str(bldata) 'zoo' series from 01/01/90 to 12/31/09 Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... Index: Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... ..- attr(*, format)= chr m/d/y ..- attr(*, origin)= Named num [1:3] 1 1 1970 .. ..- attr(*, names)= chr [1:3] month day year The array bldata is the same, only the last one is on a machine running RBloomberg, and then I tried to save bldata (and rownames of bldata in bldates) and transfer bldata to the other machine which is not a Bloomberg terminal, and the structure of bldata changes. What should I do in this case to adjust the structure? I guess I have to somehow change the class of Index and set attributes of Index and attribute names of attribute origin of attribute Index? Thank you for your help in advance! Regards, Sergey -- I'm not young enough to know everything. /Oscar Wilde Experience is one thing you can't get for nothing. /Oscar Wilde When you are finished changing, you're finished. /Benjamin Franklin Tell me and I forget, teach me and I remember, involve me and I learn. /Benjamin Franklin Luck is where preparation meets opportunity. /George Patten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] merging several dataframes from a list
Another possibility is Reduce: Reduce(function(x,y,by='pos')merge(x,y,by='pos'),mylist) pos data.x data.y data 1 A 2 69 2 B 6 23 3 C 3 96 4 D 1 72 5 E 9 51 - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Wed, 21 Jan 2009, Antje wrote: Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 - data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) - c(pos, data) df3 - df2 - df1 df2$data - c(6,2,9,7,5) df3$data - c(9,3,6,2,1) mylist - list(df1,df2,df3) names(mylist) - c(df1,df2,df3) mylist $df1 pos data 1 A2 2 B6 3 C3 4 D1 5 E9 $df2 pos data 1 A6 2 B2 3 C9 4 D7 5 E5 $df3 pos data 1 A9 2 B3 3 C6 4 D2 5 E1 If I use do.call(cbind), I'll end up with something like this pos data pos data pos data 1 A2 A6 A9 2 B6 B2 B3 3 C3 C9 C6 4 D1 D7 D2 5 E9 E5 E1 but now, I don't know anymore which data comes from which dataframe... and I have the column pos multiple times... Instead I'd like to have it like this: pos df1 df2 df3 1 A2 6 9 2 B6 2 3 3 C3 9 6 4 D1 7 2 5 E9 5 1 How, can I realize it? (The list, I'm working with has not just 3 data frames like given in my example, so I need to automize it) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Predictions with GAM
Thanks a lot for all the mails! With all the different examples I now have got it working. The problem finally after I had worked out the newd2 as supplied by Gavin was that I found the plot so strange looking. I have altered my newd2 a bit, and after your e-mails Simon I figured out how to finally plot my different graphs. The final script I used to get things running is as follows, maybe a bit different then the examples but I think it did give me the predictions I wanted. This is the version I used for the plots for all days. m3-gam(y_no~s(day,by=mapID)+mapID,family=binomial, data=mergeday) newd2 - data.frame(day = rep(seq(1, 366, length = 366), 8), mapID = rep(sort(unique(mergeday$mapID)), each = 366)) pred-data.frame(predict(m3,newd2,type=response)) names(pred) [1] predict.m3..newd2..typeresponse.. ### I need to rename the column name in something more sensible or easy, but this worked out as well. plot(pred$predict.m3..newd2..typeresponse..[1:366],type=l,ylab=Relative Habitat Use,xlab =days) If this method might not give me a correct prediction, please tell me, but I think the results looked kind of similar to my GAM plots. A mighty thank you for all the helpful replies! Robbert 2009/1/21 Simon Wood s.w...@bath.ac.uk Here's a simulated example (although really for this model structure, one might as well fit seperate models for each factor level). ## Simulate some data with factor dependent smooths n - 400 x - runif(n, 0, 1) f1 - 2 * sin(pi * x) f2 - exp(2 * x) - 3.75887 f3 - 0.2 * x^11 * (10 * (1 - x))^6 + 10 * (10 * x)^3 * (1 - x)^10 fac - as.factor(c(rep(1, 100), rep(2, 100), rep(3, 200))) fac.1 - as.numeric(fac == 1) fac.2 - as.numeric(fac == 2) fac.3 - as.numeric(fac == 3) f - f1 * fac.1 + f2 * fac.2 + f3 * fac.3 y - rpois(f,exp(f/4)) ## fit gam, with a smooth of `x' for each level of `fac' b - gam(y~s(x,by=fac)+fac,family=poisson) par(mfrow=c(2,2)) plot(b) ## produce plots on response scale, first the prediction... np - 200 newd - data.frame(x=rep(seq(0,1,length=np),3), fac=factor(c(rep(1,np),rep(2,np),rep(3,np pv - predict(b,newd,type=response) ## .. now the plotting par(mfrow=c(2,2)) ind - 1:np plot(newd$x[ind],pv[ind],type=l,xlab=x,ylab=f(x,fac=1)) ind - ind+np plot(newd$x[ind],pv[ind],type=l,xlab=x,ylab=f(x,fac=2)) ind - ind+np plot(newd$x[ind],pv[ind],type=l,xlab=x,ylab=f(x,fac=2)) On Friday 16 January 2009 14:30, Robbert Langenberg wrote: Thanks for the swift reply, I might have been a bit sloppy with describing my datasets and problem. I showed the first model as an example of the type of GAM that I had been able to use the predict function on. What I am looking for is how to predict my m3: model3-gam(y_no~s(day,by=mapID),family=binomial, data=mergeday) When I plot this I get 8 different graphs. Each showing me a different habitat type with on the x-axis days and on the y-axis s(day,2,81):mapID. With predict I was hoping to get the scale of the y-axis right for a selection of days (for example 244,304). I have tried to reform the script you gave me to match my dataset in m3, but it all did not seem to work. newd2 - data.frame(day = rep(seq(244, 304, length = 100), 8), mapID = rep(levels(mergeday$mapID), each = 100)) newd2 - data.frame(day = rep(seq(244, 304, length = 100), 8), mapID = rep(sort(unique(mergeday$mapID)), each = 100)) I am guessing it must have something to do with the by in s(day,by=mapID). I haven't come across any examples that used a GAM with by and then used the predict function. (A sample of the dataset: mapID day y_no Urban Areas and Water25 1 Urban Areas and Water26 1 Early Succesional Forest 27 0 Agriculture 28 0 Early Succesional Forest 29 0 Mature Coniferous Forest 30 0) I am sorry that I have to bother you even more with this, and I hope that my additional explanation about my problem might help solve it. Sincerely yours, Robbert Langenberg 2009/1/16 Gavin Simpson gavin.simp...@ucl.ac.uk On Fri, 2009-01-16 at 12:36 +0100, Robbert Langenberg wrote: Dear, I am trying to get a prediction of my GAM on a response type. So that I eventually get plots with the correct values on my ylab. I have been able to get some of my GAM's working with the example shown below: * model1-gam(nsdall ~ s(jdaylitr2), data=datansd) newd1 - data.frame(jdaylitr2=(244:304)) pred1 - predict.gam(model1,newd1,type=response)* Hi Robert, You want predictions for the covariate over range 244:304 for each of your 8 mapID's, yes? This is not tested, but why not something like: newd2 - data.frame(jdaylitr2 = rep(seq(244, 304, length =
[R] filling blanks with NA
Hi, I do have a data set with some missing values that appear as blanks. I want to fill these blanks with an NA. How can this be done? Thanks for your help -- View this message in context: http://www.nabble.com/filling-blanks-with-NA-tp21584278p21584278.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Linux 64-bit server crashes on large dataset
Hello everybody! We have a problem with a linux server that crashes when we try to read large datasets in R. The R code is as followed: komplett - read.spss(komplett2003aar.sav, to.data.frame =TRUE, reencode =Latin1) The information about the linux server is: Linux version 2.6.24-19-generic (bui...@king) (gcc version 4.2.3 (Ubuntu 4.2.3-2 ubuntu7) We had a memory of 15.7 GiB and swap of 5.6 GiB when the server crashes. We used about 10 GiB of the memory and the all the swap when we read in the dataset. We have now expand the swap to 25.6 GiB, but with the same memory. With these changes are we now able to read the datasets. We are not sure if that's the reason, but hope so!! Have any one experience the same? Can the size of the swap have that influence on large dataset. The dataset we tried to read was 837.2 MB. Thanks!!! Regards, Katrine __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] timeSeries and aggregation() question
Hello, I've a time series, T, for an irregular sequence of days (data for bank holidays weekends have been removed). I would like to aggregate this series by into weeks using aggregate(x, by=weeks, FUN=mean). To do this, I think that x needs to be a timeSeries object, and when I try to call timeSeries(data=T, positions=irregular.sequence.of.days) I get lots of NAs in the resulting object. (Note: I've checked that length(T)=length(irregular.sequence of days). My dates are of the form dd/mm/ in case it's relevant.) Thanks in advance! -- View this message in context: http://www.nabble.com/timeSeries-and-aggregation%28%29-question-tp21584903p21584903.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] filling blanks with NA
Hi, kayj wrote: Hi, I do have a data set with some missing values that appear as blanks. I want to fill these blanks with an NA. How can this be done? Thanks for your help Something like this? my.data-data.frame(var=c(1,2,5,,66,4,3,,67,5,3,2,1,4,32,56,23), stringsAsFactors=F) my.data$var [1] 1 2 5 66 4 3 67 5 3 2 1 4 32 56 23 my.data$var[ my.data$var== ] -NA my.data$var [1] 1 2 5 NA 66 4 3 NA 67 5 3 2 1 4 32 56 23 Kind regards, Kimmo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Multifractal detrended fluctuation analysis
Dear R-users, Has anyone written a function for multifractal detrended fluctuation analysis? The fractal package does mono-fractal DFA, but not multifractal as far as I can tell. The MF-DFA approach is presented in: J. W. Kantelhardt, S. Zschiegner, E. Koscielny-Bunde, S. Havlin, A. Bunde, and H. E. Stanley, Multifractal Detrended Fluctuation Analysis of Nonstationary Time Series, Physica A 316, 87-114 (2002). Thanks for any help you can provide. Sincerely, J. Dixon -- James A. Dixon Department of Psychology 406 Babbidge Road, Unit 1020 University of Connecticut Storrs, CT 06269-1020 Phone: (860)486-6880 Fax: (860)486-2760 email: james.di...@uconn.edu [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] forecasting issue
Hello everybody! I have a problem when I try to perform a forecast of an ARIMA model produced by an auto.arima function. Here is what I'm doing: c-auto.arima(fil[[1]],start.p=0,start.q=0,start.P=0,start.Q=0,stepwise=TRUE,stationary=FALSE,trace=TRUE) # fil[[1]] is time series of monthly data ARIMA(0,0,0)(0,1,0)[12] with drift : 1725.272 ARIMA(0,0,0)(0,1,0)[12] with drift : 1725.272 ARIMA(1,0,0)(1,1,0)[12] with drift : 1694.301 ARIMA(0,0,1)(0,1,1)[12] with drift : 1e+20 * ARIMA(1,0,0)(0,1,0)[12] with drift : 1729.999 ARIMA(1,0,0)(2,1,0)[12] with drift : 1693.12 ARIMA(1,0,0)(2,1,1)[12] with drift : 1e+20 * ARIMA(0,0,0)(2,1,0)[12] with drift : 1693.804 ARIMA(2,0,0)(2,1,0)[12] with drift : 1690.714 ARIMA(2,0,1)(2,1,0)[12] with drift : 1e+20 * ARIMA(3,0,1)(2,1,0)[12] with drift : 1e+20 * ARIMA(2,0,0)(2,1,0)[12]: 1705.069 ARIMA(2,0,0)(1,1,0)[12] with drift : 1698.130 ARIMA(2,0,0)(2,1,1)[12] with drift : 1e+20 * ARIMA(3,0,0)(2,1,0)[12] with drift : 1688.896 ARIMA(4,0,1)(2,1,0)[12] with drift : 1e+20 * ARIMA(3,0,0)(2,1,0)[12]: 1700.064 ARIMA(3,0,0)(1,1,0)[12] with drift : 1701.519 ARIMA(3,0,0)(2,1,1)[12] with drift : 1e+20 * ARIMA(4,0,0)(2,1,0)[12] with drift : 1e+20 Best model: ARIMA(3,0,0)(2,1,0)[12] with drift # this is the output of the function fore-forecast(c,h=12) # and this is the error Error en predict.Arima(object, n.ahead = h, newxreg = xreg) : 'xreg' and 'newxreg' have different numbers of columns This error only occurs when the output of the auto.arima function contanis drift. Any help is aprecciated [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Predictions with GAM
In addition to this, is it in anyway possible to get the variance in the prediction graph as a shade similar to the GAM plots? 2009/1/21 Robbert Langenberg mcre...@gmail.com Thanks a lot for all the mails! With all the different examples I now have got it working. The problem finally after I had worked out the newd2 as supplied by Gavin was that I found the plot so strange looking. I have altered my newd2 a bit, and after your e-mails Simon I figured out how to finally plot my different graphs. The final script I used to get things running is as follows, maybe a bit different then the examples but I think it did give me the predictions I wanted. This is the version I used for the plots for all days. m3-gam(y_no~s(day,by=mapID)+mapID,family=binomial, data=mergeday) newd2 - data.frame(day = rep(seq(1, 366, length = 366), 8), mapID = rep(sort(unique(mergeday$mapID)), each = 366)) pred-data.frame(predict(m3,newd2,type=response)) names(pred) [1] predict.m3..newd2..typeresponse.. ### I need to rename the column name in something more sensible or easy, but this worked out as well. plot(pred$predict.m3..newd2..typeresponse..[1:366],type=l,ylab=Relative Habitat Use,xlab =days) If this method might not give me a correct prediction, please tell me, but I think the results looked kind of similar to my GAM plots. A mighty thank you for all the helpful replies! Robbert 2009/1/21 Simon Wood s.w...@bath.ac.uk Here's a simulated example (although really for this model structure, one might as well fit seperate models for each factor level). ## Simulate some data with factor dependent smooths n - 400 x - runif(n, 0, 1) f1 - 2 * sin(pi * x) f2 - exp(2 * x) - 3.75887 f3 - 0.2 * x^11 * (10 * (1 - x))^6 + 10 * (10 * x)^3 * (1 - x)^10 fac - as.factor(c(rep(1, 100), rep(2, 100), rep(3, 200))) fac.1 - as.numeric(fac == 1) fac.2 - as.numeric(fac == 2) fac.3 - as.numeric(fac == 3) f - f1 * fac.1 + f2 * fac.2 + f3 * fac.3 y - rpois(f,exp(f/4)) ## fit gam, with a smooth of `x' for each level of `fac' b - gam(y~s(x,by=fac)+fac,family=poisson) par(mfrow=c(2,2)) plot(b) ## produce plots on response scale, first the prediction... np - 200 newd - data.frame(x=rep(seq(0,1,length=np),3), fac=factor(c(rep(1,np),rep(2,np),rep(3,np pv - predict(b,newd,type=response) ## .. now the plotting par(mfrow=c(2,2)) ind - 1:np plot(newd$x[ind],pv[ind],type=l,xlab=x,ylab=f(x,fac=1)) ind - ind+np plot(newd$x[ind],pv[ind],type=l,xlab=x,ylab=f(x,fac=2)) ind - ind+np plot(newd$x[ind],pv[ind],type=l,xlab=x,ylab=f(x,fac=2)) On Friday 16 January 2009 14:30, Robbert Langenberg wrote: Thanks for the swift reply, I might have been a bit sloppy with describing my datasets and problem. I showed the first model as an example of the type of GAM that I had been able to use the predict function on. What I am looking for is how to predict my m3: model3-gam(y_no~s(day,by=mapID),family=binomial, data=mergeday) When I plot this I get 8 different graphs. Each showing me a different habitat type with on the x-axis days and on the y-axis s(day,2,81):mapID. With predict I was hoping to get the scale of the y-axis right for a selection of days (for example 244,304). I have tried to reform the script you gave me to match my dataset in m3, but it all did not seem to work. newd2 - data.frame(day = rep(seq(244, 304, length = 100), 8), mapID = rep(levels(mergeday$mapID), each = 100)) newd2 - data.frame(day = rep(seq(244, 304, length = 100), 8), mapID = rep(sort(unique(mergeday$mapID)), each = 100)) I am guessing it must have something to do with the by in s(day,by=mapID). I haven't come across any examples that used a GAM with by and then used the predict function. (A sample of the dataset: mapID day y_no Urban Areas and Water25 1 Urban Areas and Water26 1 Early Succesional Forest 27 0 Agriculture 28 0 Early Succesional Forest 29 0 Mature Coniferous Forest 30 0) I am sorry that I have to bother you even more with this, and I hope that my additional explanation about my problem might help solve it. Sincerely yours, Robbert Langenberg 2009/1/16 Gavin Simpson gavin.simp...@ucl.ac.uk On Fri, 2009-01-16 at 12:36 +0100, Robbert Langenberg wrote: Dear, I am trying to get a prediction of my GAM on a response type. So that I eventually get plots with the correct values on my ylab. I have been able to get some of my GAM's working with the example shown below: * model1-gam(nsdall ~ s(jdaylitr2), data=datansd) newd1 - data.frame(jdaylitr2=(244:304)) pred1 - predict.gam(model1,newd1,type=response)* Hi Robert, You want
Re: [R] filling blanks with NA
Try this also: is.na(my.data$var) - which(my.data$var == ) On Wed, Jan 21, 2009 at 12:33 PM, kayj kjaj...@yahoo.com wrote: Hi, I do have a data set with some missing values that appear as blanks. I want to fill these blanks with an NA. How can this be done? Thanks for your help -- View this message in context: http://www.nabble.com/filling-blanks-with-NA-tp21584278p21584278.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two similar zoo objects with different structures, how to get same structure?
Dear Dr. Grothendieck, First of all, I realized I did not load zoo package before I tried the first str(bldata). If I load zoo and then do str(bldata) I get the following: 'zoo' series from 7305 to 14609 Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... Index: Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... ..- attr(*, format)= chr m/d/y ..- attr(*, origin)= Named num [1:3] 1 1 1970 .. ..- attr(*, names)= chr [1:3] month day year Now, I've done what you said and here is the ASCII representation of the data (I don't know if one can attach files here, and anyway I cannot attach files where I am, but the following would reproduce exactly): a - (structure(c(98.585, 98.355, 98.48, 98.585, 98.67, 98.695, 98.81, 98.865, 98.865, 98.865, 98.735, 98.805, 98.805, 97.435, 97.18, 97.165, 97.265, 97.34, 97.415, 97.445, 97.505, 97.525, 97.635, 97.625, 97.53, 97.53, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 2, 2, 2, 2, 2, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5), .Dim = c(13L, 4L), index = structure(c(14245, 14246, 14249, 14250, 14251, 14252, 14253, 14256, 14257, 14258, 14259, 14260, 14263), format = m/d/y, origin = structure(c(1, 1, 1970), .Names = c(month, day, year)), class = c(dates, times)), class = zoo, .Dimnames = list(NULL, c(ED4 COMDTY, ED12 COMDTY, FDTR INDEX, UKBRBASE INDEX Copy-paste to R prompt shows following: ED4 COMDTY ED12 COMDTY FDTR INDEX UKBRBASE INDEX 14245 98.585 97.435 0.252.0 14246 98.355 97.180 0.252.0 14249 98.480 97.165 0.252.0 14250 98.585 97.265 0.252.0 14251 98.670 97.340 0.252.0 14252 98.695 97.415 0.251.5 14253 98.810 97.445 0.251.5 14256 98.865 97.505 0.251.5 14257 98.865 97.525 0.251.5 14258 98.865 97.635 0.251.5 14259 98.735 97.625 0.251.5 14260 98.805 97.530 0.251.5 14263 98.805 97.530 0.251.5 On my Bloomberg machine, in R console, the rownames look like: ED4 COMDTY ED12 COMDTY FDTR INDEX UKBRBASE INDEX 01/01/09 98.585 97.435 0.252.0 01/02/09 98.355 97.180 0.252.0 01/05/09 98.480 97.165 0.252.0 01/06/09 98.585 97.265 0.252.0 01/07/09 98.670 97.340 0.252.0 and that is what I try to get as well. Doing: attributes(a)[[2]] - format(as.Date(attributes(a)[[2]]), %m/%d/%y) changes structure of a to: 'zoo' series from 01/01/09 to 01/19/09 Data: num [1:13, 1:4] 98.6 98.4 98.5 98.6 98.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:4] ED4 COMDTY ED12 COMDTY FDTR INDEX UKBRBASE INDEX Index: chr [1:13] 01/01/09 01/02/09 01/05/09 01/06/09 01/07/09 01/08/09 01/09/09 01/12/09 01/13/09 01/14/09 01/15/09 01/16/09 01/19/09 That is not the same structure, attributes disappeared. What am I doing wrong? Thank you in advance for your help. Regards, Sergey On Wed, Jan 21, 2009 at 15:56, Gabor Grothendieck ggrothendi...@gmail.com wrote: Please reduce your examples down to small amounts of data and use dput so that they are reproducible. On Wed, Jan 21, 2009 at 9:32 AM, Sergey Goriatchev serg...@gmail.com wrote: Dear all, I have a zoo object that has following structure: str(bldata) zoo [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, index)=Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... .. ..- attr(*, format)= chr m/d/y .. ..- attr(*, origin)= Named num [1:3] 1 1 1970 .. .. ..- attr(*, names)= chr [1:3] month day year - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... I also have a vector of dates of same length as zoo object (5219): str(bldates) chr [1:5219] 01/01/90 01/02/90 01/03/90 01/04/90 01/05/90 01/08/90 01/09/90 01/10/90 01/11/90 01/12/90 ... I do the following: attributes(bldata)[[2]] - as.Date(bldates, %m/%d/%y) and get the following: str(bldata) 'zoo' series from 1990-01-01 to 2009-12-31 Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... Index: Class 'Date' num [1:5219] 7305 7306 7307 7308 7309 ... But what I really want to get is the following: str(bldata) 'zoo' series from 01/01/90 to 12/31/09 Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... Index: Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307
Re: [R] download/retain text file structure with RCurl/getURL(): Solution
Dear list, I'm posting the solution to my problem in case others may find this useful. This code was sent to me by Phil Spector. With a bit of cleaning, it can easily be converted to a usable format. Thanks to Gabor Grothendieck, David winsemius and Martin Morgan for also sending possible solutions. Thank you all for taking the time to help, I would not have solved this on my own. ### require(RCurl) txtfile = getURL('ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt',ftp.use.epsv = FALSE) txtvec = strsplit(txtfile,'\n')[[1]] widths = c(4,rep(c(5,4,6),6)) res = read.fwf(textConnection(txtvec[9:65]),widths=widths,stringsAsFactors=FALSE) nums = c(3,4,6,7,9,10,12,13,15,16,18,19) res[,nums] = sapply(res[,nums],as.numeric) Best, Zack Date: Mon, 19 Jan 2009 11:08:48 -0800 From: spec...@stat.berkeley.edu To: zack_hol...@hotmail.com Subject: Re: [R] download/retain text file structure with RCurl/getURL() Zack - Here's a start: txtfile = getURL('ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt',ftp.use.epsv = FALSE) txtvec = strsplit(txtfile,'\n')[[1]] widths = c(4,rep(c(5,4,6),6)) res = read.fwf(textConnection(txtvec[9:65]),widths=widths,stringsAsFactors=FALSE) nums = c(3,4,6,7,9,10,12,13,15,16,18,19) res[,nums] = sapply(res[,nums],as.numeric) Hope this helps. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Mon, 19 Jan 2009, zack holden wrote: Dear list, I'm trying to download a text file directly from the internet using the RCurl package and the command getURL. Duncan Lang graciously helped me solve the first step in this problem using the following command: # txtfile - getURL('ftp://ftp.wcc.nrcs.usda.gov/data/snow/snow_course/table/history/idaho/13e19.txt', ftp.use.epsv = FALSE) # This brings the text file into R in a single long character string. I've spent many hours now trying to bring this text file into R into a sensible form. I've tried every variant of different commands in getURL help file, as well as different strsplit() commands to try to break this character string into a sensible rows and columns, to no avail. Can anyone suggest a solution for doing this? I suspect there is a getURL command I'm missing. Alternatively, do I really have to break this long character string into rows and columns that I can then assemble into a table? I'd be grateful for any advice. Thanks in advance, Zack __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error as.Date on Invalid Dates
Hi All, I have an script in R which accepts user inputs for certain parameters, particularly dates, which the user inputs as character strings. eg: date1 - 2009-01-21 The script later parses the input via the as.Date function: as.Date(date1) However, as.Date encounters an error when the string does not represent an actual date. eg: date1 - 2009-02-29 # Note: 2009 not a leap year as.Date(date1) Error in fromchar(x) : character string is not in a standard unambiguous format As I have many instances of date entries like this, date1, date2, date3, etc. , I'd like the script to error out gracefully and to be able to point the user to which date they need to correct, rather than Error in fromchar(x)..., which doesn't make it obvious what they need to do to fix the error. Ideally I'd love to send the user a message like: print(paste(date1, is an invalid date. Refer to calendar., sep= )) If anyone has any suggestions on catching this type of error and feedback which directs the user, it would be much appreciated. For reference, I am using a Windows Vista machine with: R.version.string [1] R version 2.8.0 (2008-10-20) Thanks, Brigid [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two similar zoo objects with different structures, how to get same structure?
Dear Dr. Grothendieck, My purpose in this case it to have the structure of the object on non-Bloomberg machine the same as that of the object on the Bloomberg machine. That way I am sure that whatever code I write away from Bloomberg machine will work on it when I copy the code to it. Also, I am very curious how I could change the structure of an object, in this case a zoo object. Why did the attributes disappear? How can I restore them? Kind Regards, Sergey On Wed, Jan 21, 2009 at 17:01, Gabor Grothendieck ggrothendi...@gmail.com wrote: Is your purpose to change the times in some way? If z is a zoo series you can change the times like this: library(zoo) library(chron) time(z) - ...whatever... e.g. z - zoo(1:3, 11:13) z 11 12 13 1 2 3 time(z) - as.Date(11:13) z 1970-01-12 1970-01-13 1970-01-14 1 2 3 On Wed, Jan 21, 2009 at 10:51 AM, Sergey Goriatchev serg...@gmail.com wrote: Dear Dr. Grothendieck, First of all, I realized I did not load zoo package before I tried the first str(bldata). If I load zoo and then do str(bldata) I get the following: 'zoo' series from 7305 to 14609 Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... Index: Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... ..- attr(*, format)= chr m/d/y ..- attr(*, origin)= Named num [1:3] 1 1 1970 .. ..- attr(*, names)= chr [1:3] month day year Now, I've done what you said and here is the ASCII representation of the data (I don't know if one can attach files here, and anyway I cannot attach files where I am, but the following would reproduce exactly): a - (structure(c(98.585, 98.355, 98.48, 98.585, 98.67, 98.695, 98.81, 98.865, 98.865, 98.865, 98.735, 98.805, 98.805, 97.435, 97.18, 97.165, 97.265, 97.34, 97.415, 97.445, 97.505, 97.525, 97.635, 97.625, 97.53, 97.53, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 2, 2, 2, 2, 2, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5), .Dim = c(13L, 4L), index = structure(c(14245, 14246, 14249, 14250, 14251, 14252, 14253, 14256, 14257, 14258, 14259, 14260, 14263), format = m/d/y, origin = structure(c(1, 1, 1970), .Names = c(month, day, year)), class = c(dates, times)), class = zoo, .Dimnames = list(NULL, c(ED4 COMDTY, ED12 COMDTY, FDTR INDEX, UKBRBASE INDEX Copy-paste to R prompt shows following: ED4 COMDTY ED12 COMDTY FDTR INDEX UKBRBASE INDEX 14245 98.585 97.435 0.252.0 14246 98.355 97.180 0.252.0 14249 98.480 97.165 0.252.0 14250 98.585 97.265 0.252.0 14251 98.670 97.340 0.252.0 14252 98.695 97.415 0.251.5 14253 98.810 97.445 0.251.5 14256 98.865 97.505 0.251.5 14257 98.865 97.525 0.251.5 14258 98.865 97.635 0.251.5 14259 98.735 97.625 0.251.5 14260 98.805 97.530 0.251.5 14263 98.805 97.530 0.251.5 On my Bloomberg machine, in R console, the rownames look like: ED4 COMDTY ED12 COMDTY FDTR INDEX UKBRBASE INDEX 01/01/09 98.585 97.435 0.252.0 01/02/09 98.355 97.180 0.252.0 01/05/09 98.480 97.165 0.252.0 01/06/09 98.585 97.265 0.252.0 01/07/09 98.670 97.340 0.252.0 and that is what I try to get as well. Doing: attributes(a)[[2]] - format(as.Date(attributes(a)[[2]]), %m/%d/%y) changes structure of a to: 'zoo' series from 01/01/09 to 01/19/09 Data: num [1:13, 1:4] 98.6 98.4 98.5 98.6 98.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:4] ED4 COMDTY ED12 COMDTY FDTR INDEX UKBRBASE INDEX Index: chr [1:13] 01/01/09 01/02/09 01/05/09 01/06/09 01/07/09 01/08/09 01/09/09 01/12/09 01/13/09 01/14/09 01/15/09 01/16/09 01/19/09 That is not the same structure, attributes disappeared. What am I doing wrong? Thank you in advance for your help. Regards, Sergey On Wed, Jan 21, 2009 at 15:56, Gabor Grothendieck ggrothendi...@gmail.com wrote: Please reduce your examples down to small amounts of data and use dput so that they are reproducible. On Wed, Jan 21, 2009 at 9:32 AM, Sergey Goriatchev serg...@gmail.com wrote: Dear all, I have a zoo object that has following structure: str(bldata) zoo [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, index)=Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... .. ..- attr(*, format)= chr m/d/y .. ..- attr(*, origin)= Named num [1:3] 1 1 1970 .. .. ..- attr(*, names)= chr [1:3] month day year - attr(*, dimnames)=List of 2 ..$ :
Re: [R] filling blanks with NA
I do have a data set with some missing values that appear as blanks. I want to fill these blanks with an NA. How can this be done? Thanks for your help Please help us to help you. What form are the data in? Are they in a text file, or are they in R already? What do you mean by 'blanks'? If we can reproduce your problem then we can solve it more easily. Regards, Richie. Mathematical Sciences Unit HSL ATTENTION: This message contains privileged and confidential inform...{{dropped:20}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] cv.glm: delta squared -- squared q
Dear list members, I am using a cross validation of a generalised linear model (glm). The cv.glm function (from boot package) returns an error as so-called „delta“ value. I would like to get to a (cross-validated) squared q, because I want to directly compare it to the squared correlation coefficient r. I tried to find an an equation for the raw and/or adjusted cross-validation estimate of prediction error. But actually I did not get a clear answer up to now. So it would be very kind, if someone could help me with this. Thanks in advance, Markus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] should I use rbind in my example?
Hi, I need to rbind two data frames. Each one has a header . after the rbind I would like to keep the header for each and have the two data frames separated by a line. Is this possible to do in R? For example weight_meanweight_sd.dev F 14.3 4.932883 M 34.7 10.692677 hight_meanhight_sd.dev F 35.0 7.071068 M 34.7 10.692677 -- View this message in context: http://www.nabble.com/should-I-use-rbind-in-my-example--tp21585464p21585464.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] should I use rbind in my example?
What do you want to do with it? Is this just for printing out? What other types of transformations are you intending to do? Why not just put them in a 'list' and then write your own specialized print routine. On Wed, Jan 21, 2009 at 10:30 AM, SNN s.nan...@yahoo.com wrote: Hi, I need to rbind two data frames. Each one has a header . after the rbind I would like to keep the header for each and have the two data frames separated by a line. Is this possible to do in R? For example weight_meanweight_sd.dev F 14.3 4.932883 M 34.7 10.692677 hight_meanhight_sd.dev F 35.0 7.071068 M 34.7 10.692677 -- View this message in context: http://www.nabble.com/should-I-use-rbind-in-my-example--tp21585464p21585464.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error as.Date on Invalid Dates
?try On Wed, Jan 21, 2009 at 10:55 AM, Brigid Mooney bkmoo...@gmail.com wrote: Hi All, I have an script in R which accepts user inputs for certain parameters, particularly dates, which the user inputs as character strings. eg: date1 - 2009-01-21 The script later parses the input via the as.Date function: as.Date(date1) However, as.Date encounters an error when the string does not represent an actual date. eg: date1 - 2009-02-29 # Note: 2009 not a leap year as.Date(date1) Error in fromchar(x) : character string is not in a standard unambiguous format As I have many instances of date entries like this, date1, date2, date3, etc. , I'd like the script to error out gracefully and to be able to point the user to which date they need to correct, rather than Error in fromchar(x)..., which doesn't make it obvious what they need to do to fix the error. Ideally I'd love to send the user a message like: print(paste(date1, is an invalid date. Refer to calendar., sep= )) If anyone has any suggestions on catching this type of error and feedback which directs the user, it would be much appreciated. For reference, I am using a Windows Vista machine with: R.version.string [1] R version 2.8.0 (2008-10-20) Thanks, Brigid [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two similar zoo objects with different structures, how to get same structure?
So far we have dput(a). Does that represent what you have? what you want? Can you provide both and a description in words. See the last line to every message to r-help. On Wed, Jan 21, 2009 at 11:13 AM, Sergey Goriatchev serg...@gmail.com wrote: Dear Dr. Grothendieck, My purpose in this case it to have the structure of the object on non-Bloomberg machine the same as that of the object on the Bloomberg machine. That way I am sure that whatever code I write away from Bloomberg machine will work on it when I copy the code to it. Also, I am very curious how I could change the structure of an object, in this case a zoo object. Why did the attributes disappear? How can I restore them? Kind Regards, Sergey On Wed, Jan 21, 2009 at 17:01, Gabor Grothendieck ggrothendi...@gmail.com wrote: Is your purpose to change the times in some way? If z is a zoo series you can change the times like this: library(zoo) library(chron) time(z) - ...whatever... e.g. z - zoo(1:3, 11:13) z 11 12 13 1 2 3 time(z) - as.Date(11:13) z 1970-01-12 1970-01-13 1970-01-14 1 2 3 On Wed, Jan 21, 2009 at 10:51 AM, Sergey Goriatchev serg...@gmail.com wrote: Dear Dr. Grothendieck, First of all, I realized I did not load zoo package before I tried the first str(bldata). If I load zoo and then do str(bldata) I get the following: 'zoo' series from 7305 to 14609 Data: num [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:12] ED4 COMDTY ED12 COMDTY ER4 COMDTY ER12 COMDTY ... Index: Classes 'dates', 'times' atomic [1:5219] 7305 7306 7307 7308 7309 ... ..- attr(*, format)= chr m/d/y ..- attr(*, origin)= Named num [1:3] 1 1 1970 .. ..- attr(*, names)= chr [1:3] month day year Now, I've done what you said and here is the ASCII representation of the data (I don't know if one can attach files here, and anyway I cannot attach files where I am, but the following would reproduce exactly): a - (structure(c(98.585, 98.355, 98.48, 98.585, 98.67, 98.695, 98.81, 98.865, 98.865, 98.865, 98.735, 98.805, 98.805, 97.435, 97.18, 97.165, 97.265, 97.34, 97.415, 97.445, 97.505, 97.525, 97.635, 97.625, 97.53, 97.53, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 0.25, 2, 2, 2, 2, 2, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5), .Dim = c(13L, 4L), index = structure(c(14245, 14246, 14249, 14250, 14251, 14252, 14253, 14256, 14257, 14258, 14259, 14260, 14263), format = m/d/y, origin = structure(c(1, 1, 1970), .Names = c(month, day, year)), class = c(dates, times)), class = zoo, .Dimnames = list(NULL, c(ED4 COMDTY, ED12 COMDTY, FDTR INDEX, UKBRBASE INDEX Copy-paste to R prompt shows following: ED4 COMDTY ED12 COMDTY FDTR INDEX UKBRBASE INDEX 14245 98.585 97.435 0.252.0 14246 98.355 97.180 0.252.0 14249 98.480 97.165 0.252.0 14250 98.585 97.265 0.252.0 14251 98.670 97.340 0.252.0 14252 98.695 97.415 0.251.5 14253 98.810 97.445 0.251.5 14256 98.865 97.505 0.251.5 14257 98.865 97.525 0.251.5 14258 98.865 97.635 0.251.5 14259 98.735 97.625 0.251.5 14260 98.805 97.530 0.251.5 14263 98.805 97.530 0.251.5 On my Bloomberg machine, in R console, the rownames look like: ED4 COMDTY ED12 COMDTY FDTR INDEX UKBRBASE INDEX 01/01/09 98.585 97.435 0.252.0 01/02/09 98.355 97.180 0.252.0 01/05/09 98.480 97.165 0.252.0 01/06/09 98.585 97.265 0.252.0 01/07/09 98.670 97.340 0.252.0 and that is what I try to get as well. Doing: attributes(a)[[2]] - format(as.Date(attributes(a)[[2]]), %m/%d/%y) changes structure of a to: 'zoo' series from 01/01/09 to 01/19/09 Data: num [1:13, 1:4] 98.6 98.4 98.5 98.6 98.7 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:4] ED4 COMDTY ED12 COMDTY FDTR INDEX UKBRBASE INDEX Index: chr [1:13] 01/01/09 01/02/09 01/05/09 01/06/09 01/07/09 01/08/09 01/09/09 01/12/09 01/13/09 01/14/09 01/15/09 01/16/09 01/19/09 That is not the same structure, attributes disappeared. What am I doing wrong? Thank you in advance for your help. Regards, Sergey On Wed, Jan 21, 2009 at 15:56, Gabor Grothendieck ggrothendi...@gmail.com wrote: Please reduce your examples down to small amounts of data and use dput so that they are reproducible. On Wed, Jan 21, 2009 at 9:32 AM, Sergey Goriatchev serg...@gmail.com wrote: Dear all, I have a zoo object that has following structure: str(bldata) zoo [1:5219, 1:12] 91.9 91.8 91.7 91.8 91.7 ... -
Re: [R] R and Xcode Editor
Gregor, Section 6.1 of the FAQ provides further examples. It does depend on the editor you are using. Several editors come with add-ons that support R. Recently, on the Mac specific r-sig-mac mailing list ( r-sig-...@stat.math.ethz.ch ), Smultron came up. Regards, Rob On Jan 21, 2009, at 2:42 AM, Gregor Reich wrote: Hi From the R for OS X FAQ page: (http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html ) 4.4.6 Editor (internal and external): Using AppleScript it is easy to implement Command-E and Command-Return like functionality. How? Regards, Gregor. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] seq()
HI: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 51 1 3 5 7 9 11 13 ...25 Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] seq()
G'day Felipe, On Wed, 21 Jan 2009 09:29:03 -0800 (PST) Felipe Carrillo mazatlanmex...@yahoo.com wrote: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 51 1 3 5 7 9 11 13 ...25 Are you after something like: R c(seq(27,51,by=2), seq(1,25,by=2)) [1] 27 29 31 33 35 37 39 41 43 45 47 49 51 1 3 5 7 9 11 13 15 17 19 21 23 [26] 25 or R seq(1,52,by=2)[c(14:26,1:13)] [1] 27 29 31 33 35 37 39 41 43 45 47 49 51 1 3 5 7 9 11 13 15 17 19 21 23 [26] 25 ?? HTH. Cheers, Berwin === Full address = Berwin A TurlachTel.: +65 6515 4416 (secr) Dept of Statistics and Applied Probability+65 6515 6650 (self) Faculty of Science FAX : +65 6872 3919 National University of Singapore 6 Science Drive 2, Blk S16, Level 7 e-mail: sta...@nus.edu.sg Singapore 117546http://www.stat.nus.edu.sg/~statba __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] seq()
Is this what you want: x - seq(1, 52, 2) x [1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 (x + 26) %% 52 [1] 27 29 31 33 35 37 39 41 43 45 47 49 51 1 3 5 7 9 11 13 15 17 19 21 23 25 On Wed, Jan 21, 2009 at 12:29 PM, Felipe Carrillo mazatlanmex...@yahoo.com wrote: HI: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 51 1 3 5 7 9 11 13 ...25 Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] seq()
Hi Felipe, concatenate two sequences using c(): c(seq(from=27,to=51,by=2),seq(from=1,to=25,by=2)) HTH, Stephan Felipe Carrillo schrieb: HI: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 51 1 3 5 7 9 11 13 ...25 Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] seq()
On Wed, 2009-01-21 at 09:29 -0800, Felipe Carrillo wrote: HI: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 51 1 3 5 7 9 11 13 ...25 I don't know of a way to do it with one seq() call, without further processing, but here are two solutions: First, just concatenate two seq() calls together: c(seq(27, 51, by = 2), seq(1, 25, by = 2)) which could be wrapped into a function for ease of use: bar - function(from, to, mid, by = 2) { c(seq(from = mid, to = to, by = by), seq(from = from, to = mid-by, by = by)) } Alternatively, produce the full sequence and then break if at the point you want and return the latter half plus the first half: foo - function(from, to, mid, by = 2) { SEQ - seq(from = from, to = to, by = by) midp - which(SEQ == mid) c(SEQ[midp:length(SEQ)], SEQ[1:(midp-1)]) } In both cases I take mid to be the point you want to break at, or start the *final* sequence from. foo(1, 51, by = 2, mid = 27) bar(1, 51, by = 2, mid = 27) HTH G Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% signature.asc Description: This is a digitally signed message part __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] vegan metaMDS
Hi, I'm trying to use metaMDS with a dissimilarity matrix of angles, not Bray-Curtis, and I wanted to know if there is an in-built function to produce a plot of stress values against dimensions, that could be used to determine the 'true' dimension of the solution. The number of objects is only a lowly 8 so any solution higher than 2-dimensional is not likely to be interpretable, according to Kruskal and Wish's book, but this was nevertheless required and will be useful as I gather more data. I don't have much experience with multidimensional scaling, so any advice/reading sources is/are welcome. Thanks, Radu -- Radu P. Iovita, Ph.D. Forschungsbereich Altsteinzeit Römisch-Germanisches Zentralmuseum Mainz Schloss Monrepos 56567 Neuwied Germany Web: http://radu.iovita.googlepages.com/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] X matrix deemed to be singular;
Hello, i'm tring to use a cox's model for a survival analysis. I have a dataset, this is a part: VOD SESSO fonte_sct donor RT_CGY STATOBMT TEMPO morto 1 0 F midrelated 1200 CP651 2 0 M mid 1200 2RC 5281 0 3 0 M mid unrelated 1200 1RC 218 0 4 0 M perunrelated 1200 2RC 4840 5 0 F mid 1200 1RC 3021 6 0 M midrelated 1200 1RC 12350 but when i try this command i have a warning: fit = coxph( Surv(TEMPO,morto==1)~ VOD + SESSO + fonte_sct + donor + RT_CGY + STATOBMT) Warning message: In coxph(Surv(TEMPO, morto == 1) ~ VOD + SESSO + fonte_sct + donor + : X matrix deemed to be singular; variable 10 14 15 18 20 21 22 24 25 26 why??? anyone know the solution of this?? Thanks Michele [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] seq()
It works like a charm,thank you all for your help. --- On Wed, 1/21/09, jim holtman jholt...@gmail.com wrote: From: jim holtman jholt...@gmail.com Subject: Re: [R] seq() To: mazatlanmex...@yahoo.com Cc: r-h...@stat.math.ethz.ch Date: Wednesday, January 21, 2009, 9:40 AM Is this what you want: x - seq(1, 52, 2) x [1] 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 (x + 26) %% 52 [1] 27 29 31 33 35 37 39 41 43 45 47 49 51 1 3 5 7 9 11 13 15 17 19 21 23 25 On Wed, Jan 21, 2009 at 12:29 PM, Felipe Carrillo mazatlanmex...@yahoo.com wrote: HI: Could someone help me with the seq function? I have a range of values starting from 1 to 52 but I want seq to start at 27 by=2, but when it reaches 51 start with with number 1 to 25. is this possible. I can do the basics of seq() but I can't figure how to do this one. This is how I want my sequence to look like: 27 29 31 33 35 37 51 1 3 5 7 9 11 13 ...25 Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] heatmap.2 color issue
the heatmapCol function of package MKmisc might help ... try: library(MKmisc) example(heatmapCol) Best Matthias Liu, Hao [CNTUS] wrote: Dear All: I tried to use heatmap.2 to generate hierarchical clustering using the following command: heatmap.2(datamatrix, scale=row, trace=none, col=greenred(256), labRow=genelist[,1], margins=c(10,10), Rowv=TRUE, Colv=TRUE) datamatrix is subset of a RMA normalized data subset by a genelist. The problem is a lot of times, the z-score in key are from, like -5 to 15 or -15 to 5, as a result, the zero of z distribution are are either green region or red region of the key, the resulting heatmap are either generally greenish or redish. I wonder if there is a way to make the heatmap more balanced between red and green, I tried to read the heatmap.2 help but could not get a clear idea. Thanks Hao [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dr. Matthias Kohl www.stamats.de __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] should I use rbind in my example?
Hi, This is just for print out so it looks nice. what I have is a loop that loops over my variables and calculates the mean and the sd for these variables. Then I need to rbind them so I can stack them up in one file. the problem is that only the fist header appears and the rest do not. this is because I used rbind. I am new into R , can you tell me how you put them in a 'list'?. Thanks jholtman wrote: What do you want to do with it? Is this just for printing out? What other types of transformations are you intending to do? Why not just put them in a 'list' and then write your own specialized print routine. On Wed, Jan 21, 2009 at 10:30 AM, SNN s.nan...@yahoo.com wrote: Hi, I need to rbind two data frames. Each one has a header . after the rbind I would like to keep the header for each and have the two data frames separated by a line. Is this possible to do in R? For example weight_meanweight_sd.dev F 14.3 4.932883 M 34.7 10.692677 hight_meanhight_sd.dev F 35.0 7.071068 M 34.7 10.692677 -- View this message in context: http://www.nabble.com/should-I-use-rbind-in-my-example--tp21585464p21585464.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/should-I-use-rbind-in-my-example--tp21585464p21588099.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] should I use rbind in my example?
Are you sure that you want to loop over variables for each subset, and do this within each subset? A simple way to generate summary statistics (across variables and within categories) is the summaryBy function in the doBy package: d=data.frame(wt=rnorm(100,100,10),ht=rnorm(100,2,1),sex=gl(2,1,100)) library(doBy) summaryBy(wt+ht~sex,da=d,FUN=c(mean,sd)) David Freedman SNN wrote: Hi, This is just for print out so it looks nice. what I have is a loop that loops over my variables and calculates the mean and the sd for these variables. Then I need to rbind them so I can stack them up in one file. the problem is that only the fist header appears and the rest do not. this is because I used rbind. I am new into R , can you tell me how you put them in a 'list'?. Thanks jholtman wrote: What do you want to do with it? Is this just for printing out? What other types of transformations are you intending to do? Why not just put them in a 'list' and then write your own specialized print routine. On Wed, Jan 21, 2009 at 10:30 AM, SNN s.nan...@yahoo.com wrote: Hi, I need to rbind two data frames. Each one has a header . after the rbind I would like to keep the header for each and have the two data frames separated by a line. Is this possible to do in R? For example weight_meanweight_sd.dev F 14.3 4.932883 M 34.7 10.692677 hight_meanhight_sd.dev F 35.0 7.071068 M 34.7 10.692677 -- View this message in context: http://www.nabble.com/should-I-use-rbind-in-my-example--tp21585464p21585464.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://www.nabble.com/should-I-use-rbind-in-my-example--tp21585464p21590200.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] finding row and column indices of date in multiple columns of a data frame
Hi, I have a data.frame SAMPLES with columns: Site Site# Season Day1 Day2 Day3 Day1, Day2, Day3 are class Date, the other columns are numeric or factor. I have a date mydate that may or may not be listed in my data.frame and I need to find that out. If mydate is there, I want to get the number of the data.frame row where it occurs. mydate may be in any of the three date columns and if it is there, it appears only once. Thank you for any advice and sorry if this is ni FAQ's - I couldn't find it. Gonzalo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] finding row and column indices of date in multiple columns of a data frame
Dear Gonçalo, If DF is your data set, something like this should do the job: which(DF==yourdate,arr.ind=TRUE) # Example Dates-c('01/18/2009','01/19/2009','01/20/2009','01/21/2009') DF-data.frame( +Site=sample(4), + Site#=sample(4), + Season=sample(4), +Day1=sample(Dates), + Day2= sample(Dates), + Day3=sample(Dates) + ) DF Site Site. Season Day1 Day2 Day3 12 3 1 01/21/2009 01/19/2009 01/19/2009 23 1 4 01/19/2009 01/18/2009 01/20/2009 31 2 2 01/20/2009 01/21/2009 01/18/2009 44 4 3 01/18/2009 01/20/2009 01/21/2009 which(DF=='01/21/2009',arr.ind=TRUE) row col [1,] 1 4 [2,] 3 5 [3,] 4 6 See ?which for more information. HTH, Jorge On Wed, Jan 21, 2009 at 3:30 PM, Gonçalo Ferraz gferra...@gmail.com wrote: Hi, I have a data.frame SAMPLES with columns: Site Site# Season Day1 Day2 Day3 Day1, Day2, Day3 are class Date, the other columns are numeric or factor. I have a date mydate that may or may not be listed in my data.frame and I need to find that out. If mydate is there, I want to get the number of the data.frame row where it occurs. mydate may be in any of the three date columns and if it is there, it appears only once. Thank you for any advice and sorry if this is ni FAQ's - I couldn't find it. Gonzalo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Profiling code with lots of 'apply' calls?
Hi, I have some code with a bunch of apply/sapply/lapply calls to different functions. I am trying to profile it using Rprof, however the resulting summary looks like this (output from 'R CMD Rprof'): % total % self totalseconds selfsecondsname 100.00 14.52 0.32 0.05 source 99.99 14.52 0.24 0.04 eval.with.vis 88.21 12.81 12.21 1.77 FUN 86.04 12.49 4.08 0.59 lapply 82.90 12.03 0.05 0.01 sapply 25.80 3.75 2.72 0.39 apply All of the functions called by the apply/sapply/lapply calls seem to be getting munged into a single FUN reference. Is there a way to get Rprof() and/or summaryRprof() to independently report the different functions being 'apply'-ed? Thanks. -David __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plotting activity time intervals
Dear All, I have interval data (for Mon-Sun, 00-24h) of an activity and would like to visually plot them in a matrix-like plot, where color A would be assigned to the activity, and color X to unspecified time usage. Note that the activities are not in standardised units (hours or so), but from startTime to endTime (in hrs:mins) In principle it is a bar plot where multiple bars can be stacked one on top of another, with say the x axis representing time in a day, the y axis the day of the week, without gaps between the bars? can anyone please suggest a way to plot these? Thanks Martin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Replacing dates with consecutive observations
I am working with a list of dates and I would like to replace each date with the one that comes after, ie. 1/1/07 will become 1/5/07, 1/5/07 will become 1/7/07, etc. The number of days between my dates always varies, so I can't just increase each one by 5 days or so. Does anyone know of a way I can do this in R? thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with FAME
My bad. I used system(test -r blah) to see if a file was readable, forgetting that not all Windows installations have the test program (from Cygwin) installed. I've changed this to use the R function file.access() in version 2.5, which I've just submitted to CRAN. The Windows binary should be available from there in a day or two. Jeff Boriss bor...@gmx.net writes: Dear All, I wonder whether anyone has an experience with FAME package written by Jeff Hallman. All my attempts to send him the following problem report did not succeed (the mail system says that my e-mail could not be delivered), so I turn for help to this list. I tried to use your FAME package written for R, but somehow I cannot get it working. I am using Windows XP and the newest R installation version 2.8.1. For example, if I run the following code I get the following error message: library(fame) mydb - O:/FameDB/national.db mydb fameWhats(mydb,TS21555100,getDoc = T) getfame(TS21555100,mydb) library(fame) mydb - O:/FameDB/national.db mydb [1] O:/FameDB/national.db fameWhats(mydb,TS21555100,getDoc = T) Fehler in fameWhats(mydb, TS21555100, getDoc = T) : cannot read O:/FameDB/national.db Zusätzlich: Warning message: In system(paste(test -r, path), intern = F) : test nicht gefunden getfame(TS21555100,mydb) Fehler in getfame(TS21555100, mydb) : cannot read O:/FameDB/national.db Zusätzlich: Warning message: In system(paste(test -r, path), intern = F) : test nicht gefunden --- I have a German installation and the phrase „test nicht gefunden“ means “the test has not been found”. We have a running version of FAME at our institute and from within FAME I can download this variable without problem: $open national whats TS21555100 produces: Offene Datenbanken: NATIONAL TS21555100 KOF: Vollzeitaequivalente Beschaeftigung (in 1000 Pers.) Class: SERIES DB name: NATIONAL Type: NUMERIC Created: 27-Nov-08 Index: DATE:QUARTERLY Updated: 27-Nov-08 First Value at: 75:3 Observed: SUMMED Last Value at: 08:3 Basis:DAILY OVERLAY(TS21560100, TS21555100) „Vollzeitaequivalente Beschaeftigung“ stands for „Full-time equivalent employment“ Also, I have the same error message when I run the code from the manual: seriesA - tis(1:24,start=c(2002,1),freq =12) seriesB - tis(1:104, start = c(2002, 1), tif = wmonday) documentation(seriesB) - paste(Line, 1:4, of seriesB documentation) putfame(c(mser = seriesA, wser = seriesB), db = myfame.db) Warning message: In system(paste(test -r, path), intern = F) : test nicht gefunden In the CRAN webpage I read that „ The fame package can access Fame time series databases (but also requires a Fame backend). The tis package provides time indices and time-indexed series compatible with Fame frequencies. ” However, I don’t understand what “a Fame backend” means and how it can be useful for running your package? Thank you for your help. Best wishes, Boriss Siliverstovs -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jeff __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Normality Test and T-Test
Hello R Users, Suppose I have data with the structure below: Group_Name Pre_Test Post_Test Grp_A xxx xxx Grp_A xxx xxx Grp_A xxx xxx ... Grp_B xxx xxx Grp_B xxx xxx ... Grp_Z xxx xxx Grp_Z xxx xxx Grp_Z xxx xxx Number of observations of each group are varies. I want to conduct Normality test (ad.test for Anderson Darling or pearson.test for Pearson) for each group by their pre and post values. Later, I want to do a t-test. Is there a better way to do normality test for each group without the need of loop? At this moment, the only thing I can think of is separating each group (and their pre / post test values) by creating bunch of smaller set, and do the test by way of looping. For example: group_name - unique(mydata.frame$group_name) ## or something similar for (each_group in group_name) { smaller_set - subset(mydata.frame, group_name == each_group) each_pretest - ad.test(smaller_set$pre_test) each_posttest - ad.test(smaller_set$post_test) print(paste(each_group, pre_test p-value:, each_pretest$p.value, sep = )) print(paste(each_group, post_test p-value:, each_pretest$p.value, sep = )) } and the same thing with t-test. Any idea is appreciated. Thank you. Ferry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] X matrix deemed to be singular;
Hello, i'm tring to use a cox's model for a survival analysis. I have a dataset, this is a part: VOD SESSO fonte_sct donor RT_CGY STATOBMT TEMPO morto 1 0 F midrelated 1200 CP651 2 0 M mid 1200 2RC 5281 0 3 0 M mid unrelated 1200 1RC 218 0 4 0 M perunrelated 1200 2RC 4840 5 0 F mid 1200 1RC 3021 6 0 M midrelated 1200 1RC 12350 but when i try this command i have a warning: fit = coxph( Surv(TEMPO,morto==1)~ VOD + SESSO + fonte_sct + donor + RT_CGY + STATOBMT) Warning message: In coxph(Surv(TEMPO, morto == 1) ~ VOD + SESSO + fonte_sct + donor + : X matrix deemed to be singular; variable 10 14 15 18 20 21 22 24 25 26 why??? anyone know the solution of this?? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] getting caller's environment
Hello, I'm writing a function like this: f-function(x,y,...) { ... assign(x,y,envir=?) } I need the caller (of f) 's environment for the ? so that the assignment is done at the right place. To be specific, when the code f(x,1) appears in environment A, I need the assignment of 1 to x happen in environment A. So my question is how to get the correct environment? Thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Does anyone has this paper in pdf?
de Jong, S. (1993) SIMPLS: an alternative approach to partial least squares regression. Chemometrics and Intelligent Laboratory Systems, 18, 251263 Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getting caller's environment
Try this: f - function(env = parent.frame()) env$x g - function(x=1) f() x - 2 g() # 1 On Wed, Jan 21, 2009 at 5:45 PM, Yi Zhang yizhan...@gmail.com wrote: Hello, I'm writing a function like this: f-function(x,y,...) { ... assign(x,y,envir=?) } I need the caller (of f) 's environment for the ? so that the assignment is done at the right place. To be specific, when the code f(x,1) appears in environment A, I need the assignment of 1 to x happen in environment A. So my question is how to get the correct environment? Thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] U R ready for R! Now deploy your R models via cloud computing!
Following the recent NYT article about R, I thought this group is not only ready for R but ready to take it one step further. Got models in R? Deploy and score them in ADAPA in minutes on the Amazon EC2 cloud computing infrastructure! Zementis ( http://www.zementis.com ) has been working with the R community, specifically to extend the support for the Predictive Model Markup Language (PMML) standard which allows model exchange among various statistical software tools ( http://adapasupport.zementis.com/2008/02/how-can-i-export-pmml-code-from-r.html ). If you develop your models in R, you can easily deploy and execute these models in the Zementis ADAPA scoring engine ( http://www.zementis.com/products.htm ) using the PMML standard. This not only eliminates potential memory constraints in R but also speeds execution and allows SOA-based integration. For the IT department, ADAPA delivers reliability and scalability needed for production-ready deployment and real-time predictive analytics. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] title: words in different colors?
In ?title I see the plot(cars, main = ) title(main = list(Stopping Distance versus Speed, cex=1.5, col=red, font=3)) I can't seem to generalize this to use several colors in a single title. What I'd like is in latex-ish \red{Hair color} \black{ and } \blue{Eye color} to serve also as an implicit legend for points that are plotted. -Michael -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Joint significance of more regressors in summary
Dear All, I was wondering if it is possible to generate a regression summary (it does not matter at this stage if from an lm or for example a glm estimate) in which to obtain the joint significance of a set of regressors? Examples could be looking at the joint significance level of a polynomial, or of a set of exogenous variables of which is of interest the linear combination suggested by the regression parameters. With regard to the latter, it would also be cool to visualize directly the linear combination of such group of variables, which will obviously have a regression coefficient of 1. The standard error and significance level, though, are less obvious. I would expect - please correct me if I'm wrong - that a simple ANOVA comparison between two models with and without this set of variables would give the significance level. But what if there are two sets of variables included in the model for which to find joint significance (that is, set by set)? I hope someone can help. As an example, please see the regression output below, from a quasipoisson estimation. I have two large set of eigenvector decomposition variables, one marked by _o and one by _d. For these two sets of variables, I would like to have, in the regression summary, only two lines, with Estimate, Std. Error, t-value and Pr(|t|). Obviously I can do this by hand, constructing the linear combinations, rerunning the model, and therefore obtaining a standard error and a p-value for each set. But the degrees of freedom of the model would in reality be different... Thanks in advance for any help! Cheers Roberto Patuelli Post-doc researcher Institute for Economic Research (IRE) University of Lugano Email: roberto.patue...@lu.unisi.ch Homepage: http://www.people.lu.unisi.ch/patuellr * dep.qglm - glm(dep ~ lndist + com_lang + contig + history + fta + lnarea_i + lngdppc_i + lngdp_i + island_i + landl_i + lnarea_e + lngdp_e + lngdppc_e + island_e + landl_e + + e1_o + e3_o + e4_o + e5_o + e7_o + e8_o + e9_o + e10_o + e11_o + e12_o + e13_o + e14_o + e15_o + e17_o + e18_o + e19_o + e20_o + e21_o + e22_o + e23_o + e24_o + + e1_d + e2_d + e4_d + e5_d + e7_d + e8_d + e9_d + e10_d + e12_d + e13_d + e14_d + e16_d + e17_d + e18_d + e19_d + e20_d + e22_d + e23_d + e24_d + e25_d + e26_d + e27_d + e28_d + e29_d + e30_d, family = quasipoisson (link = log)) summary(dep.qglm) Call: glm(formula = dep ~ lndist + com_lang + contig + history + fta + lnarea_i + lngdppc_i + lngdp_i + island_i + landl_i + lnarea_e + lngdp_e + lngdppc_e + island_e + landl_e + e1_o + e3_o + e4_o + e5_o + e7_o + e8_o + e9_o + e10_o + e11_o + e12_o + e13_o + e14_o + e15_o + e17_o + e18_o + e19_o + e20_o + e21_o + e22_o + e23_o + e24_o + e1_d + e2_d + e4_d + e5_d + e7_d + e8_d + e9_d + e10_d + e12_d + e13_d + e14_d + e16_d + e17_d + e18_d + e19_d + e20_d + e22_d + e23_d + e24_d + e25_d + e26_d + e27_d + e28_d + e29_d + e30_d, family = quasipoisson(link = log)) Deviance Residuals: Min 1Q Median 3QMax -137.3970-4.3775-1.8095-0.6143 195.3221 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -29.311658 0.243063 -120.593 2e-16 *** lndist -0.608668 0.009603 -63.386 2e-16 *** com_lang 0.162357 0.0210647.708 1.34e-14 *** contig0.578563 0.023609 24.506 2e-16 *** history 0.176760 0.0231137.647 2.15e-14 *** fta 0.411314 0.018823 21.851 2e-16 *** lnarea_i -0.137816 0.008402 -16.404 2e-16 *** lngdppc_i 0.003957 0.0183150.216 0.828937 lngdp_i 0.816396 0.010770 75.801 2e-16 *** island_i 0.118761 0.0306183.879 0.000105 *** landl_i -0.337145 0.040638 -8.296 2e-16 *** lnarea_e -0.054909 0.006349 -8.649 2e-16 *** lngdp_e 0.808997 0.009182 88.111 2e-16 *** lngdppc_e 0.012582 0.0123631.018 0.308837 island_e -0.202474 0.029096 -6.959 3.55e-12 *** landl_e -0.226312 0.041144 -5.501 3.84e-08 *** e1_o 0.685095 0.1306365.244 1.59e-07 *** e3_o -1.204244 0.140884 -8.548 2e-16 *** e4_o -1.311745 0.433108 -3.029 0.002460 ** e5_o -1.539045 0.278576 -5.525 3.34e-08 *** e7_o 1.722945 0.145778 11.819 2e-16 *** e8_o 1.286667 0.124809 10.309 2e-16 *** e9_o 0.359851 0.1114943.228 0.001251 ** e10_o 3.783921 0.288042 13.137 2e-16 *** e11_o 0.429692 0.1389963.091 0.001995 ** e12_o-0.707160 0.087880 -8.047 9.00e-16 *** e13_o-2.231826 0.225201 -9.910 2e-16 *** e14_o-0.256754 0.108398 -2.369 0.017865 * e15_o-0.408286 0.158939 -2.569 0.010212 * e17_o 0.297300 0.1252502.374 0.017623 * e18_o-0.969633 0.357462 -2.713 0.006683 ** e19_o-1.201774 0.116932 -10.278 2e-16 *** e20_o-1.508240
Re: [R] title: words in different colors?
2009/1/21 Michael Friendly frien...@yorku.ca: In ?title I see the plot(cars, main = ) title(main = list(Stopping Distance versus Speed, cex=1.5, col=red, font=3)) I can't seem to generalize this to use several colors in a single title. Solution from http://tolstoy.newcastle.edu.au/R/e2/help/07/09/24599.html adapted for title: plot(1:10) title(expression(hair Color * phantom( and Eye color)),col.main=red) title(expression(phantom(hair Color and ) * Eye color),col.main=blue) title(expression(phantom(hair Color ) * and * phantom(Eye color),col.main=black)) The trick is to overlay three titles, one for each colour, with the stuff not in that colour wrapped in a phantom() call to produce the correct spacing in invisible ink. There's probably other ways... Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] title: words in different colors?
Michael Friendly wrote: In ?title I see the plot(cars, main = ) title(main = list(Stopping Distance versus Speed, cex=1.5, col=red, font=3)) I can't seem to generalize this to use several colors in a single title. What I'd like is in latex-ish \red{Hair color} \black{ and } \blue{Eye color} to serve also as an implicit legend for points that are plotted. I don't know a direct way, but you could put things together by using strwidth() on each piece, then plotting them at the appropriate position using mtext. For example: technicolorTitle - function(words, colours, cex=1) { widths - strwidth(words,cex=cex) spaces - rep(strwidth( ,cex=cex), length(widths)-1) middle - mean(par(usr)[1:2]) total - sum(widths) + sum(spaces) start - c(0,cumsum(widths[-length(widths)] + spaces)) start - start + middle - total/2 mtext(words, 3, 1, at=start, adj=0, col=colours,cex=cex) } plot(1) technicolorTitle(c(Hair color, and, Eye color), c(red, black, blue)) (I didn't duplicate title()'s choice of position and font exactly, so you might want to tweak this a bit.) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plot: abline() - define line length
Hi, is there a way to define, that a line drawn via abline() should only go from for example -2 to 1 on the x-axis (with something working similiar to xlim()) ? thanks for any help! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot: abline() - define line length
I use this function (a lot): ablinepiece - function(a=NULL,b=NULL,reg=NULL,from,to,...){ # Borrowed from abline if (!is.null(reg)) a - reg if (!is.null(a) is.list(a)) { temp - as.vector(coefficients(a)) if (length(temp) == 1) { a - 0 b - temp } else { a - temp[1] b - temp[2] } } segments(x0=from,x1=to, y0=a+from*b,y1=a+to*b,...) } - Remko Duursma Post-Doctoral Fellow Centre for Plant and Food Science University of Western Sydney Hawkesbury Campus Richmond NSW 2753 Dept of Biological Science Macquarie University North Ryde NSW 2109 Australia Mobile: +61 (0)422 096908 On Thu, Jan 22, 2009 at 11:01 AM, Jörg Groß jo...@licht-malerei.de wrote: Hi, is there a way to define, that a line drawn via abline() should only go from for example -2 to 1 on the x-axis (with something working similiar to xlim()) ? thanks for any help! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plot: abline() - define line length *solved*
Thanks, that's great! Am 22.01.2009 um 01:18 schrieb Remko Duursma: I use this function (a lot): ablinepiece - function(a=NULL,b=NULL,reg=NULL,from,to,...){ # Borrowed from abline if (!is.null(reg)) a - reg if (!is.null(a) is.list(a)) { temp - as.vector(coefficients(a)) if (length(temp) == 1) { a - 0 b - temp } else { a - temp[1] b - temp[2] } } segments(x0=from,x1=to, y0=a+from*b,y1=a+to*b,...) } - Remko Duursma Post-Doctoral Fellow Centre for Plant and Food Science University of Western Sydney Hawkesbury Campus Richmond NSW 2753 Dept of Biological Science Macquarie University North Ryde NSW 2109 Australia Mobile: +61 (0)422 096908 On Thu, Jan 22, 2009 at 11:01 AM, Jörg Groß jo...@licht-malerei.de wrote: Hi, is there a way to define, that a line drawn via abline() should only go from for example -2 to 1 on the x-axis (with something working similiar to xlim()) ? thanks for any help! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Special function? [non-R query]
Greetings all, Sorry for posting what is primarily not an R question (though it will have an R target in due course). Let F(x) be the CDF of the Normal -- i.e. pnorm(x) Let f(x) be the density function -- i.e. dnorm(x) Define G(psi) = Integral[-inf,inf] F(x)*f(x)*exp(x*psi) dx Is G(psi) a known special function? If so, can anyone point me to a reference for its properties? With thanks, Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 22-Jan-09 Time: 00:58:27 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getting caller's environment
On Wed, Jan 21, 2009 at 5:57 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try this: f - function(env = parent.frame()) env$x Thanks. What if the x in env$x is an argument passed in? e.g. f - function(x, env=parent.frame()) { #assign to env$x ? } g - function(x=1) f() x - 2 g() # 1 On Wed, Jan 21, 2009 at 5:45 PM, Yi Zhang yizhan...@gmail.com wrote: Hello, I'm writing a function like this: f-function(x,y,...) { ... assign(x,y,envir=?) } I need the caller (of f) 's environment for the ? so that the assignment is done at the right place. To be specific, when the code f(x,1) appears in environment A, I need the assignment of 1 to x happen in environment A. So my question is how to get the correct environment? Thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Yi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to study the lead and lag relation of two time series?
Hi all, Is there a way to study the lead and lag relation of two time series? Let's say I have two time series, At and Bt. Is there a systematic way of concluding whether it's A leading B or B leading A and by how much? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Joint significance of more regressors in summary
try install.packages('car') ?car::linear.hypothesis hth, Kingsford Jones On Wed, Jan 21, 2009 at 4:20 PM, Roberto Patuelli roberto.patue...@lu.unisi.ch wrote: Dear All, I was wondering if it is possible to generate a regression summary (it does not matter at this stage if from an lm or for example a glm estimate) in which to obtain the joint significance of a set of regressors? Examples could be looking at the joint significance level of a polynomial, or of a set of exogenous variables of which is of interest the linear combination suggested by the regression parameters. With regard to the latter, it would also be cool to visualize directly the linear combination of such group of variables, which will obviously have a regression coefficient of 1. The standard error and significance level, though, are less obvious. I would expect - please correct me if I'm wrong - that a simple ANOVA comparison between two models with and without this set of variables would give the significance level. But what if there are two sets of variables included in the model for which to find joint significance (that is, set by set)? I hope someone can help. As an example, please see the regression output below, from a quasipoisson estimation. I have two large set of eigenvector decomposition variables, one marked by _o and one by _d. For these two sets of variables, I would like to have, in the regression summary, only two lines, with Estimate, Std. Error, t-value and Pr(|t|). Obviously I can do this by hand, constructing the linear combinations, rerunning the model, and therefore obtaining a standard error and a p-value for each set. But the degrees of freedom of the model would in reality be different... Thanks in advance for any help! Cheers Roberto Patuelli Post-doc researcher Institute for Economic Research (IRE) University of Lugano Email: roberto.patue...@lu.unisi.ch Homepage: http://www.people.lu.unisi.ch/patuellr * dep.qglm - glm(dep ~ lndist + com_lang + contig + history + fta + lnarea_i + lngdppc_i + lngdp_i + island_i + landl_i + lnarea_e + lngdp_e + lngdppc_e + island_e + landl_e + + e1_o + e3_o + e4_o + e5_o + e7_o + e8_o + e9_o + e10_o + e11_o + e12_o + e13_o + e14_o + e15_o + e17_o + e18_o + e19_o + e20_o + e21_o + e22_o + e23_o + e24_o + + e1_d + e2_d + e4_d + e5_d + e7_d + e8_d + e9_d + e10_d + e12_d + e13_d + e14_d + e16_d + e17_d + e18_d + e19_d + e20_d + e22_d + e23_d + e24_d + e25_d + e26_d + e27_d + e28_d + e29_d + e30_d, family = quasipoisson (link = log)) summary(dep.qglm) Call: glm(formula = dep ~ lndist + com_lang + contig + history + fta + lnarea_i + lngdppc_i + lngdp_i + island_i + landl_i + lnarea_e + lngdp_e + lngdppc_e + island_e + landl_e + e1_o + e3_o + e4_o + e5_o + e7_o + e8_o + e9_o + e10_o + e11_o + e12_o + e13_o + e14_o + e15_o + e17_o + e18_o + e19_o + e20_o + e21_o + e22_o + e23_o + e24_o + e1_d + e2_d + e4_d + e5_d + e7_d + e8_d + e9_d + e10_d + e12_d + e13_d + e14_d + e16_d + e17_d + e18_d + e19_d + e20_d + e22_d + e23_d + e24_d + e25_d + e26_d + e27_d + e28_d + e29_d + e30_d, family = quasipoisson(link = log)) Deviance Residuals: Min 1Q Median 3QMax -137.3970-4.3775-1.8095-0.6143 195.3221 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -29.311658 0.243063 -120.593 2e-16 *** lndist -0.608668 0.009603 -63.386 2e-16 *** com_lang 0.162357 0.0210647.708 1.34e-14 *** contig0.578563 0.023609 24.506 2e-16 *** history 0.176760 0.0231137.647 2.15e-14 *** fta 0.411314 0.018823 21.851 2e-16 *** lnarea_i -0.137816 0.008402 -16.404 2e-16 *** lngdppc_i 0.003957 0.0183150.216 0.828937 lngdp_i 0.816396 0.010770 75.801 2e-16 *** island_i 0.118761 0.0306183.879 0.000105 *** landl_i -0.337145 0.040638 -8.296 2e-16 *** lnarea_e -0.054909 0.006349 -8.649 2e-16 *** lngdp_e 0.808997 0.009182 88.111 2e-16 *** lngdppc_e 0.012582 0.0123631.018 0.308837 island_e -0.202474 0.029096 -6.959 3.55e-12 *** landl_e -0.226312 0.041144 -5.501 3.84e-08 *** e1_o 0.685095 0.1306365.244 1.59e-07 *** e3_o -1.204244 0.140884 -8.548 2e-16 *** e4_o -1.311745 0.433108 -3.029 0.002460 ** e5_o -1.539045 0.278576 -5.525 3.34e-08 *** e7_o 1.722945 0.145778 11.819 2e-16 *** e8_o 1.286667 0.124809 10.309 2e-16 *** e9_o 0.359851 0.1114943.228 0.001251 ** e10_o 3.783921 0.288042 13.137 2e-16 *** e11_o 0.429692 0.1389963.091 0.001995 ** e12_o-0.707160 0.087880 -8.047 9.00e-16 *** e13_o-2.231826 0.225201 -9.910 2e-16 *** e14_o-0.256754 0.108398 -2.369 0.017865 * e15_o-0.408286 0.158939
Re: [R] how to study the lead and lag relation of two time series?
Try a search on cross correlation time series HTH, Jim Porzak TGN.com San Francisco, CA http://www.linkedin.com/in/jimporzak use R! Group SF: http://ia.meetup.com/67/ On Wed, Jan 21, 2009 at 5:17 PM, Michael comtech@gmail.com wrote: Hi all, Is there a way to study the lead and lag relation of two time series? Let's say I have two time series, At and Bt. Is there a systematic way of concluding whether it's A leading B or B leading A and by how much? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Normality Test and T-Test
One of: ?by ?aggregate ?ave Next time include the package name where these functions come from AND code that creates an example data situation and you will increase your probability of getting a more prompt and complete reply. -- David Winsemius On Jan 21, 2009, at 4:54 PM, Ferry wrote: Hello R Users, Suppose I have data with the structure below: Group_Name Pre_Test Post_Test Grp_A xxx xxx Grp_A xxx xxx Grp_A xxx xxx ... Grp_B xxx xxx Grp_B xxx xxx ... Grp_Z xxx xxx Grp_Z xxx xxx Grp_Z xxx xxx Number of observations of each group are varies. I want to conduct Normality test (ad.test for Anderson Darling or pearson.test for Pearson) for each group by their pre and post values. Later, I want to do a t-test. Is there a better way to do normality test for each group without the need of loop? At this moment, the only thing I can think of is separating each group (and their pre / post test values) by creating bunch of smaller set, and do the test by way of looping. For example: group_name - unique(mydata.frame$group_name) ## or something similar for (each_group in group_name) { smaller_set - subset(mydata.frame, group_name == each_group) each_pretest - ad.test(smaller_set$pre_test) each_posttest - ad.test(smaller_set$post_test) print(paste(each_group, pre_test p-value:, each_pretest$p.value, sep = )) print(paste(each_group, post_test p-value:, each_pretest$p.value, sep = )) } and the same thing with t-test. Any idea is appreciated. Thank you. Ferry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem with cex=0.1 when making jpegs
I am using the following script to make .jpg files. jpeg('plotx.jpg') ddat -read.table(file,header=T) attach(ddat) tdat-read.table(file1) plot(xx1,yy1,type='p',pch=1,col=blue,cex=0.2,xlim=c(0,3.5),ylim=c(-75,75)) points(tdat,col=green,pch=1,cex=0.2) dev.off() The problem is that I want the points to be very small; however, if I make cex any smaller than 0.2 the plot in the .jpg file is blank. If I run the commands from the console (on a Mac) - with the exception of jpeg() and dev.off() then it works even if cex 0.2. I've tried making .ps files and converting to .jpg but then I run into different problems with the animation software (imageJ). Thanks for any suggestions -- View this message in context: http://www.nabble.com/Problem-with-cex%3D0.1-when-making-jpegs-tp21593744p21593744.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getting caller's environment
Try this: myassign - function(x, val, env = parent.frame()) assign(deparse(substitute(x)), val, env) myassign(x, 3) x # 3 On Wed, Jan 21, 2009 at 8:03 PM, Yi Zhang yizhan...@gmail.com wrote: On Wed, Jan 21, 2009 at 5:57 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try this: f - function(env = parent.frame()) env$x Thanks. What if the x in env$x is an argument passed in? e.g. f - function(x, env=parent.frame()) { #assign to env$x ? } g - function(x=1) f() x - 2 g() # 1 On Wed, Jan 21, 2009 at 5:45 PM, Yi Zhang yizhan...@gmail.com wrote: Hello, I'm writing a function like this: f-function(x,y,...) { ... assign(x,y,envir=?) } I need the caller (of f) 's environment for the ? so that the assignment is done at the right place. To be specific, when the code f(x,1) appears in environment A, I need the assignment of 1 to x happen in environment A. So my question is how to get the correct environment? Thanks for any suggestions! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Yi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.