[R] Plot Arrows with Angle and length
Dears, The arrows command uses the start and end coordinates of each vector, but I have the starting coordinates, azimuth, and length. So, There are package that plot this arrows? Example: > x<- c(1,2,4) > y<- c(2,3,5) > Azimuth<- c(45,90,180) > Length<- c(1,0.5,1) Thanks, Julio [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 Arrows with Angle and length
It's just basic trig to convert. -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Mar 29, 2017 at 6:44 AM, julio cesar oliveira wrote: > Dears, > > The arrows command uses the start and end coordinates of each vector, but I > have the starting coordinates, azimuth, and length. > > So, There are package that plot this arrows? > > Example: > >> x<- c(1,2,4) >> y<- c(2,3,5) >> Azimuth<- c(45,90,180) >> Length<- c(1,0.5,1) > > > Thanks, > > Julio > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Archive format
Hello, we are collecting information on the subject of research data management in German on the webplatform: www.forschungsdaten.info One of the topics, which we are writing about, is how to *archive* data. Unfortunately, none of us in the project is an expert with respect to R and so I would like to ask the list, what they recommend? A related question is to do with the sharing of data. We have already asked some academics, who have basically replied that they don't really know other than to strongly recommend a plain text format. We would also like to know, if members of the list recommend converting formats from commercial software such as S-Plus, Terr, SPSS etc. to an R-compatible format for long term archivation? Are there any general rules and best practices, when it comes to archiving (and sharing) statistical data and statistical programs? Any comments would be much appreciated! Joe -- B 1003 Kommunikations-, Informations-, Medienzentrum (KIM) Universitaet Konstanz t: ++49-7531-883234 e: joe.g...@uni-konstanz.de __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 Arrows with Angle and length
> The arrows command uses the start and end coordinates of each vector, but > I have the starting coordinates, azimuth, and length. > > So, There are package that plot this arrows? > > Example: > > > x<- c(1,2,4) > > y<- c(2,3,5) > > Azimuth<- c(45,90,180) > > Length<- c(1,0.5,1) May be packages out there but if it's a quick fix you want, roll your own. arrows.az <- function(x, y, azimuth, length, ..., units=c("degrees", "radians")) { units <- match.arg(units) az.rad <- switch(units, degrees=azimuth*pi/180, radians=azimuth ) arrows(x, y, x+cos(az.rad)*length, y+sin(az.rad)*length, ...) } plot(0:6, 0:6, type="n") arrows.az(x, y, Azimuth, Length) "..." means you can pass all the other options to arrows() S Ellison > > > Thanks, > > Julio > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] valaddin (0.1.0): Make your functions more robust
Dear fellow R users, valaddin (0.1.0) has been published on CRAN: https://cran.r-project.org/package=valaddin Using valaddin, you can transform an existing function into a function with input validation, without having to rewrite it with stop() or stopifnot() statements. It therefore provides a convenient and consistent way to make your functions more robust and more predictable, either interactively at the console, or in your programs. To learn more, see: - The landing page of the source repository: https://github.com/egnha/valaddin - The package vignette, which gives an overview of use cases: https://cran.r-project.org/package=valaddin/vignettes/valaddin.html Bug reports and other feedback are welcome at the issues page on GitHub: https://github.com/egnha/valaddin/issues - Eugene Ha ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 Arrows with Angle and length - correction
Apologies; 'length' is an arrows() argument. Use something else - see below. > > x<- c(1,2,4) > > y<- c(2,3,5) > > Azimuth<- c(45,90,180) > > Length<- c(1,0.5,1) May be packages out there but if it's a quick fix you want, roll your own. arrows.az <- function(x, y, azimuth, size, ..., units=c("degrees", "radians")) { #Using 'size' to avoid clash with arrows(..., length=...) units <- match.arg(units) az.rad <- switch(units, degrees=azimuth*pi/180, radians=azimuth ) arrows(x, y, x+cos(az.rad)*size, y+sin(az.rad)*size, ...) } plot(0:6, 0:6, type="n") arrows.az(x, y, Azimuth, Length) "..." means you can pass all the other options to arrows() S Ellison > > > Thanks, > > Julio > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code. *** This email and any attachments are confidential. Any use...{{dropped:8}} __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Archive format
Joe: 1. This may be the wrong forum for this question, as this list is about R programming issues. However, I don't know what the right forum should be. You might consider stats.stackexchange.com. Some IT forum might be better (but which???) 2. A google search on "data formats for archiving" (or similar) seemed to produce many useful hits. I think you'd learn more from that than you would here. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Wed, Mar 29, 2017 at 1:44 AM, Joe Gain wrote: > Hello, > > we are collecting information on the subject of research data management in > German on the webplatform: > > www.forschungsdaten.info > > One of the topics, which we are writing about, is how to *archive* data. > Unfortunately, none of us in the project is an expert with respect to R and > so I would like to ask the list, what they recommend? A related question is > to do with the sharing of data. We have already asked some academics, who > have basically replied that they don't really know other than to strongly > recommend a plain text format. > > We would also like to know, if members of the list recommend converting > formats from commercial software such as S-Plus, Terr, SPSS etc. to an > R-compatible format for long term archivation? Are there any general rules > and best practices, when it comes to archiving (and sharing) statistical > data and statistical programs? > > Any comments would be much appreciated! > Joe > > -- > B 1003 > Kommunikations-, Informations-, Medienzentrum (KIM) > Universitaet Konstanz > > t: ++49-7531-883234 > e: joe.g...@uni-konstanz.de > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Archive format
Dear Joe, I'd choose a plain text format. They can be read and parsed with a very wide range of software. That is IMHO a much more important factor for long term archivation that file size or the ease to read it with specific software. The choice between tab-delimited, comma separated values, XML, JSON, ... will depend upon the data (and the metadata). Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey 2017-03-29 10:44 GMT+02:00 Joe Gain : > Hello, > > we are collecting information on the subject of research data management in > German on the webplatform: > > www.forschungsdaten.info > > One of the topics, which we are writing about, is how to *archive* data. > Unfortunately, none of us in the project is an expert with respect to R and > so I would like to ask the list, what they recommend? A related question is > to do with the sharing of data. We have already asked some academics, who > have basically replied that they don't really know other than to strongly > recommend a plain text format. > > We would also like to know, if members of the list recommend converting > formats from commercial software such as S-Plus, Terr, SPSS etc. to an > R-compatible format for long term archivation? Are there any general rules > and best practices, when it comes to archiving (and sharing) statistical > data and statistical programs? > > Any comments would be much appreciated! > Joe > > -- > B 1003 > Kommunikations-, Informations-, Medienzentrum (KIM) > Universitaet Konstanz > > t: ++49-7531-883234 > e: joe.g...@uni-konstanz.de > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] RMySQL system error: 10060
I have a project with a connection that was working properly on the same device. I usually work on two devices and pull my updates from a remote repo. I suddenly got the error below. However, I could connect from the same device through MySQL workbench. I posted the on [Stackoverflow]( http://stackoverflow.com/questions/43073782/rmysql-system-error-10060) library(RMySQL) con <- dbConnect(RMySQL::MySQL(), host = "xxx", dbname="yyy", user = "zzz", password = "") Error in .local(drv, ...) : Failed to connect to database: Error: Lost connection to MySQL server at 'reading authorization packet', system error: 10060 > sessionInfo() R version 3.3.1 (2016-06-21)Platform: x86_64-w64-mingw32/x64 (64-bit)Running under: Windows >= 8 x64 (build 9200) locale:[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages:[1] stats graphics grDevices utils datasets methods base other attached packages:[1] RMySQL_0.10.10 DBI_0.4-1 loaded via a namespace (and not attached):[1] tools_3.3.1 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 an unexpected extra row when merging two dataframes
Hello everyone, Hope you are all doing great. So I have two datasets: -dataset1Frame: which contains the historical number of transits from october 1st, 1985 up to march 1, 2017. It has two columns, one called TransitDate and the other called Transits. dataset1Frame is a table comming from an SQL Server Database. -TransitDateFrame: a made up dataframe that goes from october 1st, 1985 up to the last date available in dataset1Frame. Note: The reason why I made up TransitDataFrame is because, since sometimes dataset1Frame has missing observations (some dates do not exist), and I just want to make sure I have all the dates available from october 1, 1985 up to the last available observation. The idea is to leave the transits that do exist as they come, and add the dates missing as aditional rows (observations) with a value of NA for the transits. That being said, here is the code: >install.packages("src/lubridate_1.6.0.zip", lib=".", repos=NULL, verbose=TRUE) >library(lubridate, lib.loc=".", verbose=TRUE) >library(forecast) >library(tseries) >library(stats) >library(stats4) >dataset1 <-read.table("CONTAINERTESTDATA.txt") >dataset1Frame<-data.frame(dataset1) >dataset1Frame$TransitDate<-as.Date(dataset1Frame$TransitDate, "%Y-%m-%d") >TransitDate<-seq(as.Date("1985-10-01"), as.Date(dataset1Frame[nrow(dataset1Frame),1]), "months") >TransitDate["Transits"]<-NA >TransitDateFrame<-data.frame(TransitDate) >NewTransitsFrame<-merge(dataset1Frame,TransitDateFrame, all.y=TRUE) #Output from resulting dataframes >TransitDateFrame >NewTransitsFrame Why is there an additional row(observation) with a value of NA if I specified that the dataframe should only go to the last observation? There should be 378 observations at the end and I get 379 observations instead. The reason I am doing it this way is because this is how I got to fill in the gaps in dates (whenever there are nonexistent observations/missing data). Any guidance will be greatly appreciated. I am attaching a .txt file as a reference, Best regards, Paul TransitDate Transits 1-Oct-8555 1-Nov-8566 1-Dec-8514 1-Jan-8648 1-Feb-8657 1-Mar-8649 1-Apr-8670 1-May-8619 1-Jun-8627 1-Jul-8628 1-Aug-8627 1-Sep-8666 1-Oct-8626 1-Nov-8652 1-Dec-8629 1-Jan-8759 1-Feb-8747 1-Mar-8759 1-Apr-8746 1-May-8739 1-Jun-8711 1-Jul-8742 1-Aug-8714 1-Sep-8738 1-Oct-8734 1-Nov-8721 1-Dec-8739 1-Jan-8818 1-Feb-8867 1-Mar-8835 1-Apr-8849 1-May-8836 1-Jun-8822 1-Jul-8869 1-Aug-8869 1-Sep-8833 1-Oct-8826 1-Nov-8843 1-Dec-8811 1-Jan-8946 1-Feb-8922 1-Mar-8953 1-Apr-8946 1-May-8949 1-Jun-8964 1-Jul-8916 1-Aug-8931 1-Sep-8922 1-Oct-8937 1-Nov-8932 1-Dec-8960 1-Jan-9065 1-Feb-9072 1-Mar-9014 1-Apr-9035 1-May-9025 1-Jun-909 1-Jul-9056 1-Aug-9047 1-Sep-9062 1-Oct-9039 1-Nov-9036 1-Dec-9060 1-Jan-9148 1-Feb-9156 1-Mar-9142 1-Apr-9132 1-May-9128 1-Jun-9164 1-Jul-9130 1-Aug-9112 1-Sep-9129 1-Oct-9163 1-Nov-9138 1-Dec-9164 1-Jan-9216 1-Feb-9270 1-Mar-9249 1-Apr-9234 1-May-9234 1-Jun-9269 1-Jul-9211 1-Aug-9220 1-Sep-9217 1-Oct-9251 1-Nov-9241 1-Dec-9218 1-Jan-9316 1-Feb-9315 1-Mar-9343 1-Apr-9358 1-May-9343 1-Jun-9349 1-Jul-9369 1-Aug-9345 1-Sep-9368 1-Oct-9319 1-Nov-9318 1-Dec-9330 1-Jan-9443 1-Feb-9428 1-Mar-9413 1-Apr-9447 1-May-9471 1-Jun-9467 1-Jul-9428 1-Aug-9444 1-Sep-9461 1-Oct-9473 1-Nov-9468 1-Dec-9461 1-Jan-9534 1-Feb-9570 1-Mar-9516 1-Apr-9568 1-May-9540 1-Jun-9560 1-Jul-9569 1-Aug-9553 1-Sep-9520 1-Oct-9528 1-Nov-9561 1-Dec-9541 1-Jan-9625 1-Feb-9640 1-Mar-9631 1-Apr-9624 1-May-9657 1-Jun-9622 1-Jul-9644 1-Aug-9619 1-Sep-9624 1-Oct-9650 1-Nov-9646 1-Dec-9650 1-Jan-9722 1-Feb-9731 1-Mar-9732 1-Apr-9745 1-May-9719 1-Jun-9740 1-Jul-9722 1-Aug-9760 1-Sep-9748 1-Oct-9768 1-Nov-9745 1-Dec-9742 1-Jan-9833 1-Feb-9870 1-Mar-9841 1-Apr-9867 1-May-9824 1-Jun-9829 1-Jul-987
Re: [R] Plot Arrows with Angle and length
II find using complex numbers makes for less typing with this sort of thing. Note the use of plot(asp=1,...) to force equal scales on both axes so the angles are right. (I think asp=1 should have been the default when plotting complex numbers, but too late now.) > azimuthToNative <- function(degreesClockwise) { + # convert degrees clockwise from north to + # radians counter-clockwise from east. + (90-degreesClockwise)/180*base::pi + } > start <- complex(real=x, imaginary=y) > end <- start + complex(modulus = Length, argument = azimuthToNative(Azimuth)) > plot(c(start, end), type="n", asp=1) # asp=1 => equal scaling on both axes > arrows(Re(start),Im(start),Re(end),Im(end)) # no complex method for arrows Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Mar 29, 2017 at 6:44 AM, julio cesar oliveira wrote: > Dears, > > The arrows command uses the start and end coordinates of each vector, but I > have the starting coordinates, azimuth, and length. > > So, There are package that plot this arrows? > > Example: > >> x<- c(1,2,4) >> y<- c(2,3,5) >> Azimuth<- c(45,90,180) >> Length<- c(1,0.5,1) > > > Thanks, > > Julio > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Archive format
The relevance to R (and therefore R-help) of this question is marginal at best. R might not be the language of choice when you go retrieve the data. Also, this question seems dangerously close to a troll, because the obvious answer is that the data should be in an open format but if you are not currently working with data in an open format then you increase the cost of archiving and risk losing information up front by extracting it from a proprietary format, and balancing those concerns is more political than technical. Note that there exist open binary formats, and the goals of your archiving task and nature of the data would have to be considered in deciding which of the many to use. My own experience has been that plain text survives time best, but YMMV. -- Sent from my phone. Please excuse my brevity. On March 29, 2017 1:44:21 AM PDT, Joe Gain wrote: >Hello, > >we are collecting information on the subject of research data >management >in German on the webplatform: > >www.forschungsdaten.info > >One of the topics, which we are writing about, is how to *archive* >data. >Unfortunately, none of us in the project is an expert with respect to R > >and so I would like to ask the list, what they recommend? A related >question is to do with the sharing of data. We have already asked some >academics, who have basically replied that they don't really know other > >than to strongly recommend a plain text format. > >We would also like to know, if members of the list recommend converting > >formats from commercial software such as S-Plus, Terr, SPSS etc. to an >R-compatible format for long term archivation? Are there any general >rules and best practices, when it comes to archiving (and sharing) >statistical data and statistical programs? > >Any comments would be much appreciated! >Joe __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 Arrows with Angle and length
Hi Julio, Perhaps "vectorField" (plotrix) is what you are looking for. Jim On Thu, Mar 30, 2017 at 12:44 AM, julio cesar oliveira wrote: > Dears, > > The arrows command uses the start and end coordinates of each vector, but I > have the starting coordinates, azimuth, and length. > > So, There are package that plot this arrows? > > Example: > >> x<- c(1,2,4) >> y<- c(2,3,5) >> Azimuth<- c(45,90,180) >> Length<- c(1,0.5,1) > > > Thanks, > > Julio > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] I want to delete "yhat" and transpose "Response" into a vector
Hi R'ers: I need a little help. Thanks in advance. Bruce dd<- read.csv("C:/R_Data/firstRdata.csv", sep=",", header=TRUE) dd<- data.frame(yhat,Response) attach(dd) dd <- dd[order(-yhat),] dd # delete yhat and transpose Response into a vector Attached is dataset. -- Bruce __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] I want to delete "yhat" and transpose "Response" into a vector
On 29/03/2017 6:14 PM, BR_email wrote: Hi R'ers: I need a little help. Thanks in advance. Bruce dd<- read.csv("C:/R_Data/firstRdata.csv", sep=",", header=TRUE) dd<- data.frame(yhat,Response) attach(dd) dd <- dd[order(-yhat),] dd # delete yhat and transpose Response into a vector Sounds like a homework assignment. We don't do those. Duncan Murdoch __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] I want to delete "yhat" and transpose "Response" into a vector
Hi Bruce, Before we get into the whole business of why your CSV file is lying by the side of the road to the R help list, let's deal with a few more important things. 1) You have created a data frame "dd" by reading your CSV file (we hope). 2) You have then overwritten this with two vectors (?) of data. I looks very much like you have tried to do this with two columns of the first "dd". As you haven't specified that these belong to "dd', it is likely that the two vectors were already defined in the environment in which you did this. 3) OR you have already attached "dd" previously and that prevented the error that would have been generated in 2. 4) You have then reordered 'dd' with the _negative_ values of yhat. 5) You then asked us how to delete the "yhat" column: dd<-dd[,-which(names(dd)=="yhat")] and transpose (! - I think you mean "transform") Response into a vector: transform: dd$Response Jim On Thu, Mar 30, 2017 at 9:14 AM, BR_email wrote: > Hi R'ers: > I need a little help. > Thanks in advance. > Bruce > > dd<- read.csv("C:/R_Data/firstRdata.csv", sep=",", header=TRUE) > dd<- data.frame(yhat,Response) > attach(dd) > > dd <- dd[order(-yhat),] > dd > # delete yhat and transpose Response into a vector > Attached is dataset. > > -- > Bruce > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] I want to delete "yhat" and transpose "Response" into a vector
Duncan, it's not a homework assignment. Jim, thank you. Bruce __ Bruce Ratner PhD The Significant Statistician™ (516) 791-3544 Statistical Predictive Analytics -- www.DMSTAT1.com Machine-Learning Data Mining -- www.GenIQ.net > On Mar 29, 2017, at 6:29 PM, Duncan Murdoch wrote: > > Duncan __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] I want to delete "yhat" and transpose "Response" into a vector
Duncan, it's not a homework assignment. Thanks. Bruce __ > On Mar 29, 2017, at 6:29 PM, Duncan Murdoch wrote: > >> On 29/03/2017 6:14 PM, BR_email wrote: >> Hi R'ers: >> I need a little help. >> Thanks in advance. >> Bruce >> >> dd<- read.csv("C:/R_Data/firstRdata.csv", sep=",", header=TRUE) >> dd<- data.frame(yhat,Response) >> attach(dd) >> >> dd <- dd[order(-yhat),] >> dd >> # delete yhat and transpose Response into a vector > > Sounds like a homework assignment. We don't do those. > > Duncan Murdoch > > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 an unexpected extra row when merging two dataframes
first of all when you read the data in you get 379 rows of data since you did not say 'header = TRUE' in the read.table. Here is what the first 6 lines of you data are: > dataset1 <- read.table('/users/jh52822/downloads/containertestdata.txt') > > str(dataset1) 'data.frame': 379 obs. of 2 variables: $ V1: Factor w/ 379 levels "1-Apr-00","1-Apr-01",..: 379 333 301 80 145 113 239 18 270 207 ... $ V2: Factor w/ 66 levels "10","11","12",..: 66 46 57 5 39 48 40 61 10 18 ... > View(dataset1) > head(dataset1) V1 V2 1 TransitDate Transits 21-Oct-85 55 31-Nov-85 66 41-Dec-85 14 51-Jan-86 48 61-Feb-86 57 > You need to learn to use 'str' to look at the structure. So when you are converting the dates, you will get an NA because the first row has "TransitDate". Now if you had used 'header = TRUE', you data would look like this: > dataset1 <- read.table('/users/jh52822/downloads/containertestdata.txt', + header = TRUE, + as.is = TRUE # prevent conversion to factors + ) > > str(dataset1) 'data.frame': 378 obs. of 2 variables: $ TransitDate: chr "1-Oct-85" "1-Nov-85" "1-Dec-85" "1-Jan-86" ... $ Transits : int 55 66 14 48 57 49 70 19 27 28 ... > head(dataset1) TransitDate Transits 11-Oct-85 55 21-Nov-85 66 31-Dec-85 14 41-Jan-86 48 51-Feb-86 57 61-Mar-86 49 > So try again. Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Wed, Mar 29, 2017 at 11:02 AM, Paul Bernal wrote: > Hello everyone, > > Hope you are all doing great. So I have two datasets: > > -dataset1Frame: which contains the historical number of transits from > october 1st, 1985 up to march 1, 2017. It has two columns, one called > TransitDate and the other called Transits. dataset1Frame is a table comming > from an SQL Server Database. > > -TransitDateFrame: a made up dataframe that goes from october 1st, 1985 up > to the last date available in dataset1Frame. > > Note: The reason why I made up TransitDataFrame is because, since sometimes > dataset1Frame has missing observations (some dates do not exist), and I > just want to make sure I have all the dates available from october 1, 1985 > up to the last available observation. > The idea is to leave the transits that do exist as they come, and add the > dates missing as aditional rows (observations) with a value of NA for the > transits. > > That being said, here is the code: > >>install.packages("src/lubridate_1.6.0.zip", lib=".", repos=NULL, > verbose=TRUE) >>library(lubridate, lib.loc=".", verbose=TRUE) >>library(forecast) >>library(tseries) >>library(stats) >>library(stats4) > >>dataset1 <-read.table("CONTAINERTESTDATA.txt") > > >>dataset1Frame<-data.frame(dataset1) > >>dataset1Frame$TransitDate<-as.Date(dataset1Frame$TransitDate, "%Y-%m-%d") > >>TransitDate<-seq(as.Date("1985-10-01"), > as.Date(dataset1Frame[nrow(dataset1Frame),1]), "months") > >>TransitDate["Transits"]<-NA > >>TransitDateFrame<-data.frame(TransitDate) > >>NewTransitsFrame<-merge(dataset1Frame,TransitDateFrame, all.y=TRUE) > > #Output from resulting dataframes > >>TransitDateFrame > >>NewTransitsFrame > > Why is there an additional row(observation) with a value of NA if I > specified that the dataframe should only go to the last observation? There > should be 378 observations at the end and I get 379 observations instead. > > The reason I am doing it this way is because this is how I got to fill in > the gaps in dates (whenever there are nonexistent observations/missing > data). > > Any guidance will be greatly appreciated. > > I am attaching a .txt file as a reference, > > Best regards, > > Paul > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Parallel programming.
Hello everyone, I have general question about parallel programming. I'm doing simulations that involves bootstrap. For now I'm using parLapply only for bootstrap part and then function "replicate" for simulations. It is very long function, so here is a short version: simfun=function(data,n,alpha){ #code{} cl <- makeCluster(detectCores()) clusterExport(cl,c("data"), envir=environment()) clusterExport(cl,c("n"), envir=environment()) q=1000; #Bootstrap - zero-corrected stepwise selection repl=*parLapply*(cl=cl,1:q,function(i,dataB=data,smpl=n,...){ dataB <- dataB[sample(nrow(dataB),size=n,replace=TRUE),] m1=glm(y~x1+x2+x3+t,family=binomial,data=dataB) S=step(m1,direction="backward",trace=F); Sstep=summary(S);Sstep if (any(rownames(Sstep$coefficients)=="t")==TRUE){ beta.Step.zero=Sstep$coefficients[paste0("t"), ][1] }else{ beta.Step.zero=0; } return(beta.Step.zero) }) stopCluster(cl) beta.Step.zero.v=(do.call("rbind", repl)); beta.Step.zero=mean(beta.Step.zero.v);beta.Step.zero lower.step.zero=quantile(beta.Step.zero.v, c(.025, .975))[1];lower.step.zero upper.step.zero=quantile(beta.Step.zero.v, c(.025, .975))[2];upper.step.zero Ind.Step.zero=as.integer(bt > lower.step.zero & bt < upper.step.zero); Len.Step.zero=upper.step.zero-lower.step.zero; #more code{} return(list(Ind.Step.zero=Ind.Step.zero,Len.Step.zero=Len.Step.zero,lower.step.zero=lower.step.zero,beta.Step.zero=beta.Step.zero,upper.step.zero=upper.step.zero)) } simN=1000; repl=*replicate*(simN,simfun(data=data,n=n,alpha=0.025)) For now this code works in waves, each step in replicate it starts to use all CPU and then stops. Is there the way to convert such function to 100% parallel programming function? Or any way to make it faster? Thank you in advance. Ariel -- *I like to pretend I'm alone*. *Completely alone*. *Maybe post-apocalypse or plague*... *Whatever*. *No-one left to act normal for. No need to hide who I really am. It would be... freeing*. *...* [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Calculating between and within subject coefficient of variation
Let's say I have repeated measures of some outcome on some subjects. I want to be able to calculate the within and between subject coefficient of variation for this measure. An example data frame is: df<-data.frame(ID = c(1,1,1,2,2,2,3,3,3), DAY = c(0,3,6, 0,3,6, 0,3,6), VALUE = c(1,2,3,4,5,5,2,3,4) ) Where ID is the identifier of the subject, DAY is the day the measurement was taken, and VALUE is the measurement taken on that day. Can someone suggest an efficient way to do this? I assume I need to start with repeated measures ANOVA or mixed model but I'm having trouble figuring out how to use the outputs from those to get the numbers I want. Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.