[R] DateTime wrong when exporting to csv in R
Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[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] DateTime wrong when exporting to csv in R
Tried that..does not help :( On Wed, Aug 20, 2014 at 8:03 AM, Saurabh Agrawal sagra...@idrcglobal.com wrote: Maybe converting POSIXct to character string using format before writing to csv will help. On 20 August 2014 17:23, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[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. -- Sneha Bishnoi +14047235469 H. Milton Stewart School of Industrial Systems Engineering Georgia Tech [[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] DateTime wrong when exporting to csv in R
This problem is in Excel or your use thereof, not in R, and is therefore not technically on topic here. FWIW I am aware that localization of Excel can change the default date formats for input. I suspect that your installation of Excel has a different default date format than you are using in R (like MDY) that is attempting to convert the file before you start messing with formats. This would incorrectly interpret some cells and fail entirely for others (leaving those cells as strings). My suggestion is to have R output MDY rather than DMY. If that is not satisfactory then you probably ought to ask for help in an Excel forum. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On August 20, 2014 4:53:41 AM PDT, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[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.
Re: [R] loading saved files with objects in same names
On Tue, Aug 19, 2014 at 1:30 AM, Jinsong Zhao jsz...@yeah.net wrote: Hi there, I have several saved data files (e.g., A.RData, B.RData and C.RData). In each file, there are some objects with same names but different contents. Now, I need to compare those objects through plotting. However, I can't find a way to load them into a workspace. The only thing I can do is to rename them and then save and load again. Is there a convenient to load those objects? Thanks a lot in advance. The technique of loading into an environment already mentioned can be cleaned up and put into a function. First lets save a thing called x into two files with different values: x=first save(x,file=f.RData) x=second save(x,file=s.RData) This little function wraps the loading: getFrom=function(file, name){e=new.env();load(file,env=e);e[[name]]} So now I can get 'x' from the first file - the value is returned from `getFrom` so I can assign it to anything: x1 = getFrom(f.RData,x) x1 [1] first x2 = getFrom(s.RData,x) x2 [1] second And I can even loop over RData files and read in all the `x`s into a vector: sapply(c(f.RData,s.RData),function(f){getFrom(f,x)}) f.RData s.RData first second (on second thoughts, possibly 'loadFrom' is a better name) 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] loading saved files with objects in same names
On 20/08/2014, 8:58 AM, Barry Rowlingson wrote: On Tue, Aug 19, 2014 at 1:30 AM, Jinsong Zhao jsz...@yeah.net wrote: Hi there, I have several saved data files (e.g., A.RData, B.RData and C.RData). In each file, there are some objects with same names but different contents. Now, I need to compare those objects through plotting. However, I can't find a way to load them into a workspace. The only thing I can do is to rename them and then save and load again. Is there a convenient to load those objects? Thanks a lot in advance. The technique of loading into an environment already mentioned can be cleaned up and put into a function. First lets save a thing called x into two files with different values: x=first save(x,file=f.RData)) x=second save(x,file=s.RData) This little function wraps the loading: getFrom=function(file, name){e=new.env();load(file,env=e);e[[name]]} So now I can get 'x' from the first file - the value is returned from `getFrom` so I can assign it to anything: x1 = getFrom(f.RData,x) x1 [1] first x2 = getFrom(s.RData,x) x2 [1] second And I can even loop over RData files and read in all the `x`s into a vector: sapply(c(f.RData,s.RData),function(f){getFrom(f,x)}) f.RData s.RData first second (on second thoughts, possibly 'loadFrom' is a better name) That's a nice little function. You could also have lsFrom, that lists the objects stored in the file, along the same lines: lsFrom - function(file, all.names = FALSE, pattern) { e - new.env() load(file, envir = e) ls(e, all.names = all.names, pattern = pattern) } 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] DateTime wrong when exporting to csv in R
Hi If you really need to have minutes and seconds etc in excel then use a package that can write datetime columns that excel can read eg. access rather that csv. Microsoft is well known for changing dates and date formats - remember excel is a worksheet application not a database - caveat emptor. If you use a formatted date that excel can recognize then excel has less of a tendency to change it. Datetime is a pain in any language because of the irregularity of time. Beware MS does not get it right if you are using dates from ca 1890 to 1910 Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sneha Bishnoi Sent: Wednesday, 20 August 2014 22:14 To: Saurabh Agrawal Cc: r-help Subject: Re: [R] DateTime wrong when exporting to csv in R Tried that..does not help :( On Wed, Aug 20, 2014 at 8:03 AM, Saurabh Agrawal sagra...@idrcglobal.com wrote: Maybe converting POSIXct to character string using format before writing to csv will help. On 20 August 2014 17:23, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[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. -- Sneha Bishnoi +14047235469 H. Milton Stewart School of Industrial Systems Engineering Georgia Tech [[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.
Re: [R] Negative values on output
It appears you posted in HTML and what we get is an almost useles set of data. It is much better to supply it using dput() (and always post to the list in plain text not HTML. See https://github.com/hadley/devtools/wiki/Reproducibility of http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for some helpful hints on how to post to the R-Help list/ John Kane Kingston ON Canada -Original Message- From: sam_l_cruicksh...@hotmail.com Sent: Tue, 19 Aug 2014 19:09:13 +0100 To: r-help@r-project.org Subject: [R] Negative values on output Good afternoon, I am completed a linear regression model which I personally am happy with the output and residual charts (although they are a bit bunched). I have been using visreg() to visualise my data, and although I have logged the dependent variable (as it is cost data), on one of the graphical outputs I am getting negative fitted values for one of the Continents. Attached is the data used, below is the code for the model and graph. If anyone has any ideas I would hugely appreciate it, I tried a glm with log link too and this didn't help. LM22 - lm(logTotal ~ logArea + Continent + factor(Method1) + Popdens, data=dummy) Output Residuals: Min 1Q Median 3Q Max -1.22742 -0.31675 -0.00909 0.28885 1.20224 Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept)-1.409720.77661 -1.815 0.081506 . logArea 0.038110.04041 0.943 0.354619ContinentAsia 3.51165 0.80009 4.389 0.000182 ***ContinentAustralasia3.485490.97433 3.577 0.001454 ** ContinentEurope 2.448290.82369 2.972 0.006452 ** ContinentGlobal 2.379101.00668 2.363 0.026197 * ContinentNorth America 2.279530.62960 3.621 0.001303 ** ContinentSouth America 3.609970.77627 4.650 9.22e-05 ***factor(Method1)21.112590.38386 2.898 0.007696 ** factor(Method1)30.825190.47470 1.738 0.094459 . factor(Method1)4 -0.067370.67341 -0.100 0.921104Popdens -0.142610.31675 -0.450 0.656435---Signif. codes: 0 *** 0.001 ** 0.01 * 0.05 . 0.1 1 Residual standard error: 0.6151 on 25 degrees of freedom (12 observations deleted due to missingness)Multiple R-squared: 0.6998, Adjusted R-squared: 0.5677 F-statistic: 5.297 on 11 and 25 DF, p-value: 0.0002714 visreg(LM22) gives me a graph with Africa being within the realm of negative Total which is impossible. If you tell me how can provide the data and graphs, but the email was kicked back with them in. [[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. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ 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] as.Date woes
Hi all, I have recently started working with Date objects and find the experience unsettling, to put it mildly. The help for as.Date says, in part: ## S3 method for class 'character' as.Date(x, format = , ...) x: An object to be converted. format: A character string. If not specified, it will try ‘%Y-%m-%d’ then ‘%Y/%m/%d’ on the first non-‘NA’ element, and give an error if neither works. If I read this correctly, as.Date(2012-04-30) and as.Date(2012-04-30, format = ) should give the same results, but they don't: as.Date(2012-04-30) [1] 2012-04-30 as.Date(2012-04-30, format = ) [1] 2014-08-20 Note the latter gives today's date, without any warning or message. What method is called in the latter case? Another issue I am running into, that is probably connected to the 'format' argument above, is trying to convert a numeric or character in the same call. Basically, I would like to call as.Date(object, format = , origin = 1970-1-1) where object can be a Date, numeric or character, in the hope that the appropriate method will be selected and will ignore unnecessary arguments. Here's what I get: as.Date( as.numeric(Sys.Date()), origin = 1970-1-1) [1] 2014-08-20 Correct as.Date( as.numeric(Sys.Date()), origin = 1970-1-1, format = ) [1] 2059-04-08 ??? Excuse the coarse language, but WTF??? The first call confirms that the origin is specified correctly, and the second gives a date removed from the origin by twice the number of days than the actual input?? as.numeric(Sys.Date()) [1] 16302 as.numeric(as.Date( as.numeric(Sys.Date()), origin = 1970-1-1)) [1] 16302 as.numeric(as.Date( as.numeric(Sys.Date()), origin = 1970-1-1, format = )) [1] 32604 Thanks in advance for any pointers! Peter PS: I know my R is not the most up to date, but I haven't found anything about Date mentioned in the changelog for the 3.x series. sessionInfo() R version 3.0.2 Patched (2013-10-08 r64039) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=en_US.utf8LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base __ 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] as.Date woes
Never mind... the solution was to read the source code of as.Date.character. It turns out the default format= is meaningless. If 'format' is not given in the call to as.Date, it is NOT assumed to be , and the function gives very different results from a call where the argument format= is given. G... Peter On Wed, Aug 20, 2014 at 11:56 AM, Peter Langfelder peter.langfel...@gmail.com wrote: Hi all, I have recently started working with Date objects and find the experience unsettling, to put it mildly. The help for as.Date says, in part: ## S3 method for class 'character' as.Date(x, format = , ...) x: An object to be converted. format: A character string. If not specified, it will try ‘%Y-%m-%d’ then ‘%Y/%m/%d’ on the first non-‘NA’ element, and give an error if neither works. If I read this correctly, as.Date(2012-04-30) and as.Date(2012-04-30, format = ) should give the same results, but they don't: as.Date(2012-04-30) [1] 2012-04-30 as.Date(2012-04-30, format = ) [1] 2014-08-20 Note the latter gives today's date, without any warning or message. What method is called in the latter case? Another issue I am running into, that is probably connected to the 'format' argument above, is trying to convert a numeric or character in the same call. Basically, I would like to call as.Date(object, format = , origin = 1970-1-1) where object can be a Date, numeric or character, in the hope that the appropriate method will be selected and will ignore unnecessary arguments. Here's what I get: as.Date( as.numeric(Sys.Date()), origin = 1970-1-1) [1] 2014-08-20 Correct as.Date( as.numeric(Sys.Date()), origin = 1970-1-1, format = ) [1] 2059-04-08 ??? Excuse the coarse language, but WTF??? The first call confirms that the origin is specified correctly, and the second gives a date removed from the origin by twice the number of days than the actual input?? as.numeric(Sys.Date()) [1] 16302 as.numeric(as.Date( as.numeric(Sys.Date()), origin = 1970-1-1)) [1] 16302 as.numeric(as.Date( as.numeric(Sys.Date()), origin = 1970-1-1, format = )) [1] 32604 Thanks in advance for any pointers! Peter PS: I know my R is not the most up to date, but I haven't found anything about Date mentioned in the changelog for the 3.x series. sessionInfo() R version 3.0.2 Patched (2013-10-08 r64039) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=en_US.utf8LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base __ 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] DateTime wrong when exporting to csv in R
Maybe converting POSIXct to character string using format before writing to csv will help. On 20 August 2014 17:23, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[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. [[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] DateTime wrong when exporting to csv in R
Could you please post your code and some sample data? http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example On 20 August 2014 17:43, Sneha Bishnoi sneha.bish...@gmail.com wrote: Tried that..does not help :( On Wed, Aug 20, 2014 at 8:03 AM, Saurabh Agrawal sagra...@idrcglobal.com wrote: Maybe converting POSIXct to character string using format before writing to csv will help. On 20 August 2014 17:23, Sneha Bishnoi sneha.bish...@gmail.com wrote: Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[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. -- Sneha Bishnoi +14047235469 H. Milton Stewart School of Industrial Systems Engineering Georgia Tech [[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] DateTime wrong when exporting to csv in R
On Aug 20, 2014, at 4:53 AM, Sneha Bishnoi wrote: Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . What does same number form mean? So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.0006 2014-08-14 16:13:08.850 A -SB [[alternative HTML version deleted]] The reason you are asked to post in plain text is to avoid the line wrapping and other mangling of data that html formatting causes. I've reformatted your posting to be what appears to be a very incomplete representation of your file. I substituted tabs for the varying number of space -- opened and empty excel workbook -- formatted the first and third columns with a custom format for a date-time in the POSIX standard format (or a close as I can get to that in Excel, anyway) as illustrated in the attached .png file. -- open the tab-separated file. Dates and times all agree. 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. David Winsemius Alameda, CA, 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] Euclidean Distance in 3 Dimensions
R Community - I am attempting to write a function that will calculate the distance between points in 3 dimensional space for unique regions (e.g. localized brain regions such as the frontal lobe). For example I'm looking to compare each point in region 45 to every other region in 45 to establish if they are a distance of 8 or more apart. I can do this linearly comparing each distance to the previous but this is not comparing all points. structure(list(Cluster.Index = c(46L, 46L, 46L, 46L, 46L, 45L, 45L, 45L, 45L, 45L, 44L, 44L, 44L, 44L, 44L, 43L, 43L, 43L, 43L, 43L), Value = c(8.21, 7.96, 7.85, 7.83, 7.8, 5.38, 4.56, 4.5, 4, 3.99, 5.42, 4.82, 4.21, 4.18, 3.91, 4.79, 4.27, 3.24, 3.06, 3.04), x = c(33L, 38L, 37L, 36L, 38L, 47L, 42L, 43L, 44L, 42L, 50L, 41L, 39L, 41L, 44L, 46L, 45L, 45L, 41L, 46L), y = c(15L, 12L, 12L, 13L, 13L, 91L, 84L, 84L, 95L, 96L, 69L, 70L, 65L, 65L, 59L, 41L, 40L, 46L, 44L, 47L), z = c(41L, 38L, 41L, 39L, 33L, 39L, 40L, 42L, 44L, 45L, 34L, 36L, 30L, 35L, 39L, 53L, 47L, 61L, 52L, 57L), X = c(NA, 6.557438524302, 3.16227766016838, 2.44948974278318, 6.32455532033676, 78.7464284904401, 8.66025403784439, 2.23606797749979, 11.2249721603218, 2.44948974278318, 30.2324329156619, 9.2736184954957, 8.06225774829855, 5.3851648071345, 7.81024967590665, 22.8910462845192, 6.16441400296898, 15.2315462117278, 10.0498756211209, 7.68114574786861 )), .Names = c(Cluster.Index, Value, x, y, z, X), row.names = c(NA, 20L), class = data.frame) mainDat - data.frame() for(i in 2:nrow(dat)){ tempDist - (sqrt((dat$x[i] - dat$x[i-1])^2 + (dat$y[i] - dat$y[i-1])^2 + (dat$z[i] - dat$z[i-1])^2)) dat$X[i] - c(tempDist) if(dat$Cluster.Index[i] != dat$Cluster.Index[i-1]){ mainDat - rbind(mainDat, dat[i,]) } if((dat$Cluster.Index[i] == dat$Cluster.Index[i-1])) { if(tempDist 8){ mainDat - rbind(mainDat, dat[i,]) } } } -- *Edward H Patzelt | Clinical Science PhD StudentPsychology | Harvard University * [[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] Euclidean Distance in 3 Dimensions
?dist from the help dist {stats}R Documentation Distance Matrix Computation Description This function computes and returns the distance matrix computed by using the specified distance measure to compute the distances between the rows of a data matrix. Is this what you want? Computing on a matrix whose rows are your x, y, and z values? On Aug 20, 2014, at 1:12 PM, Patzelt, Edward patz...@g.harvard.edu wrote: R Community - I am attempting to write a function that will calculate the distance between points in 3 dimensional space for unique regions (e.g. localized brain regions such as the frontal lobe). For example I'm looking to compare each point in region 45 to every other region in 45 to establish if they are a distance of 8 or more apart. I can do this linearly comparing each distance to the previous but this is not comparing all points. structure(list(Cluster.Index = c(46L, 46L, 46L, 46L, 46L, 45L, 45L, 45L, 45L, 45L, 44L, 44L, 44L, 44L, 44L, 43L, 43L, 43L, 43L, 43L), Value = c(8.21, 7.96, 7.85, 7.83, 7.8, 5.38, 4.56, 4.5, 4, 3.99, 5.42, 4.82, 4.21, 4.18, 3.91, 4.79, 4.27, 3.24, 3.06, 3.04), x = c(33L, 38L, 37L, 36L, 38L, 47L, 42L, 43L, 44L, 42L, 50L, 41L, 39L, 41L, 44L, 46L, 45L, 45L, 41L, 46L), y = c(15L, 12L, 12L, 13L, 13L, 91L, 84L, 84L, 95L, 96L, 69L, 70L, 65L, 65L, 59L, 41L, 40L, 46L, 44L, 47L), z = c(41L, 38L, 41L, 39L, 33L, 39L, 40L, 42L, 44L, 45L, 34L, 36L, 30L, 35L, 39L, 53L, 47L, 61L, 52L, 57L), X = c(NA, 6.557438524302, 3.16227766016838, 2.44948974278318, 6.32455532033676, 78.7464284904401, 8.66025403784439, 2.23606797749979, 11.2249721603218, 2.44948974278318, 30.2324329156619, 9.2736184954957, 8.06225774829855, 5.3851648071345, 7.81024967590665, 22.8910462845192, 6.16441400296898, 15.2315462117278, 10.0498756211209, 7.68114574786861 )), .Names = c(Cluster.Index, Value, x, y, z, X), row.names = c(NA, 20L), class = data.frame) mainDat - data.frame() for(i in 2:nrow(dat)){ tempDist - (sqrt((dat$x[i] - dat$x[i-1])^2 + (dat$y[i] - dat$y[i-1])^2 + (dat$z[i] - dat$z[i-1])^2)) dat$X[i] - c(tempDist) if(dat$Cluster.Index[i] != dat$Cluster.Index[i-1]){ mainDat - rbind(mainDat, dat[i,]) } if((dat$Cluster.Index[i] == dat$Cluster.Index[i-1])) { if(tempDist 8){ mainDat - rbind(mainDat, dat[i,]) } } } -- *Edward H Patzelt | Clinical Science PhD StudentPsychology | Harvard University * [[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. Don McKenzie Research Ecologist Pacific Wildland Fire Sciences Lab US Forest Service Affiliate Professor School of Environmental and Forest Sciences University of Washington d...@uw.edu __ 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] ordinary kriging: the edges of the polygons are ignored
Hi All, I am trying to do some kriging of a floor, based on a number of heat sensors. My data looks like this: sensortempxy 1 1 1.25437406 390 2960 2 2 0.64384594 830 2960 3 3 1.52067733 1420 2960 4 4 1.21441928 3127 2920 5 5 1.04227694 4005 2920 6 6 1.90084852 400 1960 7 7 1.58530250 835 1880 8 8 1.23060971 1130 1960 9 9 0.92749453 1550 1950 10 10 0.76638878 1995 1960 11 11 0.84247092 2540 1950 12 12 0.9329 3300 1880 13 13 0.61610170 4000 1870 14 14 1.06967332 395 1330 15 15 0.72970917 845 1330 16 16 0.60216970 1135 1300 17 17 0.44648551 1570 1275 18 18 2.49863724 2010 1290 19 19 0.71619206 2540 1320 20 20 1.50984666 3140 1275 21 21 -0.06540552 4000 1258 22 22 1.20017747 400 685 23 23 1.05820693 1575 640 24 24 2.25086655 1830 625 25 25 0.69296059 3120 625 26 26 0.69324786 3990 605 and the floor plan describes the edges of the floor thus: xy 1 210 3200 2 210 420 3 1510 420 4 1510 100 5 4090 100 6 4090 3200 7 2947 3200 8 2947 2850 9 1647 2850 10 1647 3200 11 210 3200 12 210 3200 I run these commands: house2 - list(data.frame(house$x, house$y)) plot(house.y ~house.x, type = 'l', house2[[1]]) points(U[,3], U[,4], pch = 20) housekrig=kriging(U[,3],U[,4],U[,2],polygons=house2,lags = 5) image(housekrig, xlim = extendrange(U[,3]), ylim = extendrange(U[,4]), col = rev(heat.colors(100))) and I noticed that the kriging area does not respect the floor plan. In fact, if I do: points(U[,3], U[,4], pch = 20) the sensors and not in the same place, and the kriging has ignored the edges of the polygons altogether. So my question is, how do I have a kriging of the *whole* surface, based on my sensors? Any suggestion is welcome, especially if the data does not require reformatting (or if the reformatting is straightforward)! Best F PS I have contacted the maintainer of the package about the issue but I had no reply, and I’d need to solve this one way or another sooner, rather than later. signature.asc Description: Message signed with OpenPGP using GPGMail __ 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] Fwd: DateTime wrong when exporting to csv in R
The image file I prepared and attached did not make it through. Trying again. -- David Begin forwarded message: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] DateTime wrong when exporting to csv in R Date: August 20, 2014 1:48:14 PM PDT To: Sneha Bishnoi sneha.bish...@gmail.com Cc: r-help R-help@r-project.org On Aug 20, 2014, at 4:53 AM, Sneha Bishnoi wrote: Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . What does same number form mean? So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[alternative HTML version deleted]] The reason you are asked to post in plain text is to avoid the line wrapping and other mangling of data that html formatting causes. I've reformatted your posting to be what appears to be a very incomplete representation of your file. I substituted tabs for the varying number of space -- opened and empty excel workbook -- formatted the first and third columns with a custom format for a date-time in the POSIX standard format (or a close as I can get to that in Excel, anyway) as illustrated in the attached .png file. -- open the tab-separated file. Dates and times all agree. 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. David Winsemius Alameda, CA, USA David Winsemius Alameda, CA, 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] DateTime wrong when exporting to csv in R
On Aug 20, 2014, at 1:48 PM, David Winsemius wrote: On Aug 20, 2014, at 4:53 AM, Sneha Bishnoi wrote: Hi All! This seems to be trival but I am not able to find a solution for it. I have a dataframe with datetime columns in form of (%d/%m/%y %H:%M:%OS). I write it to csv file. Whne i open the csv file the date time format are in some number form . What does same number form mean? So even if I use custome settings from excel to change it into date time format, it gives me wrong value. My data frame is as below: PostDateStatus ArrTime NumGuests 2014-08-14 16:13:08.850 O2012-01-13 00:00:00.000 6 2014-08-14 16:13:08.850 A -SB [[alternative HTML version deleted]] The reason you are asked to post in plain text is to avoid the line wrapping and other mangling of data that html formatting causes. I've reformatted your posting to be what appears to be a very incomplete representation of your file. I substituted tabs for the varying number of space -- opened and empty excel workbook -- formatted the first and third columns with a custom format for a date-time in the POSIX standard format (or a close as I can get to that in Excel, anyway) as illustrated in the attached .png file. The server seems to be rejecting PNG files (although they were accpted earlier). So trying with a PDF version of the PNG file: Excel_dat_fmt.pdf Description: Adobe PDF document -- David. -- open the tab-separated file. Dates and times all agree. 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. David Winsemius Alameda, CA, 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. David Winsemius Alameda, CA, 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] Installing RODBC
I tried installing RODBC but got the following message: Checks were yes until the following checking sql.h usability... no checking sql.h presence... no checking for sql.h... no checking sqlext.h usability... no checking sqlext.h presence... no checking for sqlext.h... no configure: error: ODBC headers sql.h and sqlext.h not found ERROR: configuration failed for package ‘RODBC’ * removing ‘/home/bill/R/x86_64-pc-linux-gnu-library/3.1/RODBC’ Apparently RODBC was there when R was installed, but library() shows it is not there now, although the DBI package is. Best ideas for installing RODBC? Bill __ 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] Installing RODBC
On Aug 20, 2014, at 5:43 PM, William Deese williamde...@gmail.com wrote: I tried installing RODBC but got the following message: Checks were yes until the following checking sql.h usability... no checking sql.h presence... no checking for sql.h... no checking sqlext.h usability... no checking sqlext.h presence... no checking for sqlext.h... no configure: error: ODBC headers sql.h and sqlext.h not found ERROR: configuration failed for package ‘RODBC’ * removing ‘/home/bill/R/x86_64-pc-linux-gnu-library/3.1/RODBC’ Apparently RODBC was there when R was installed, but library() shows it is not there now, although the DBI package is. Best ideas for installing RODBC? Bill You are missing the indicated header files, which are required if you are building the package from source. As per the extensive vignette that Prof. Ripley has provided: http://cran.r-project.org/web/packages/RODBC/vignettes/RODBC.pdf in Appendix A, which describes Installation, you will find: For other systems the driver manager of choice is likely to be unixODBC, part of almost all Linux distributions and with sources downloadable from http://www.unixODBC.org. In Linux binary distributions it is likely that package unixODBC-devel or unixodbc-dev or some such will be needed. Thus, for whatever Linux distribution you are using, install the relevant RPMs or Debs or ... Also, for future reference, there is a specific mailing list for DB related queries: https://stat.ethz.ch/mailman/listinfo/r-sig-db and a search of the list archives, for example using rseek.org, would likely result in your finding queries and answers to this same issue over the years. Regards, Marc Schwartz __ 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] Line Graph greater than 2 variables on plot
Hi all, I was wondering if anyone knew how to construct a multiple line graph on R, where there are 2 (or more) sets of data points plotted against some x axis of data, and you can draw a line on the graph connecting each set of data points. for example: time..years. incidencerural urban 1 2004 295.4 19.019.50 2 2005 824.1 19.959.98 3 2006 1078.0 20.70 10.35 4 2007 1258.0 21.26 10.63 5 2008 1800.0 21.83 10.91 6 2009 1890.0 18.939.47 7 2010 1999.0 19.41 9.71 8 2011 2261.019.899.95 9 2012 2321.0 20.28 10.14 Idea: a) I am planning plot a graph of data illustrated above where on Y-axis we can have data in sets INCIDENCE, RURAL and URBAN and on X-axis the points in set TIME..YEARS. b) Would like to be able to draw three lines ,connecting the points for each set of INCIDENCE, RURAL and URBAN over TIME..YEARS. I have tried really hard to find something but wasn't successful, the latest information I received after doing the command shown underneath was: plot(data1$time..years.,data1$incidence,main=Plot illustrating diarrhoeal incidence over time, xlab=Time(years),ylab=Diarrhoeal incidence,ylim=range(data[c(incidence,rural,urban)]),typel, col=2) Error: unexpected string constant in plot(data1$time..years.,data1$incidence,main=Plot illustrating diarrhoeal incidence over time, xlab=Time(years),ylab=Diarrhoeal incidence,ylim=range(data[c(incidence,rural,urban)]) Many thanks, W [[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] Installing RODBC
My guess is that you do not have the appropriate ODBC development library for your operating system installed. It is not unusual that R packages that provide interfaces to outside APIs require that those resources be installed and configured in the operating system before the relevant R library can be installed. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On August 20, 2014 3:43:44 PM PDT, William Deese williamde...@gmail.com wrote: I tried installing RODBC but got the following message: Checks were yes until the following checking sql.h usability... no checking sql.h presence... no checking for sql.h... no checking sqlext.h usability... no checking sqlext.h presence... no checking for sqlext.h... no configure: error: ODBC headers sql.h and sqlext.h not found ERROR: configuration failed for package ‘RODBC’ * removing ‘/home/bill/R/x86_64-pc-linux-gnu-library/3.1/RODBC’ Apparently RODBC was there when R was installed, but library() shows it is not there now, although the DBI package is. Best ideas for installing RODBC? Bill __ 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] Line Graph greater than 2 variables on plot
Hi Try something like (as you have not given a reproducible example) library(lattice) xyplot(y1 + y2+ y3 ... ~ x, data = your data.frame, type = b, allow.multiple = TRUE) Read ?xyplot CAREFULLY as there are many possibilities you may want to have a look at library(lattice) ?useOuterStrips and other functions in the package See http://lmdvr.r-forge.r-project.org/figures/figures.html for ideas Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Waseq Ziaie Sent: Thursday, 21 August 2014 08:55 To: r-help@r-project.org Subject: [R] Line Graph greater than 2 variables on plot Hi all, I was wondering if anyone knew how to construct a multiple line graph on R, where there are 2 (or more) sets of data points plotted against some x axis of data, and you can draw a line on the graph connecting each set of data points. for example: time..years. incidencerural urban 1 2004 295.4 19.019.50 2 2005 824.1 19.959.98 3 2006 1078.0 20.70 10.35 4 2007 1258.0 21.26 10.63 5 2008 1800.0 21.83 10.91 6 2009 1890.0 18.939.47 7 2010 1999.0 19.41 9.71 8 2011 2261.019.899.95 9 2012 2321.0 20.28 10.14 Idea: a) I am planning plot a graph of data illustrated above where on Y-axis we can have data in sets INCIDENCE, RURAL and URBAN and on X-axis the points in set TIME..YEARS. b) Would like to be able to draw three lines ,connecting the points for each set of INCIDENCE, RURAL and URBAN over TIME..YEARS. I have tried really hard to find something but wasn't successful, the latest information I received after doing the command shown underneath was: plot(data1$time..years.,data1$incidence,main=Plot illustrating diarrhoeal incidence over time, xlab=Time(years),ylab=Diarrhoeal incidence,ylim=range(data[c(incidence,rural,urban)]),typel, col=2) Error: unexpected string constant in plot(data1$time..years.,data1$incidence,main=Plot illustrating diarrhoeal incidence over time, xlab=Time(years),ylab=Diarrhoeal incidence,ylim=range(data[c(incidence,rural,urban)]) Many thanks, W [[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] ggplot2: how to jitter spaghetti plot so slopes are preserved
Hi, Suppose I have a the data frame given by: dput(toy.df) structure(list(id = c(1, 2, 1, 2), time = c(1L, 1L, 2L, 2L), value = c(1, 2, 2, 3)), .Names = c(id, time, value), row.names = c(NA, 4L), class = data.frame) that is: toy.df id time value 1 11 1 2 21 2 3 12 2 4 22 3 I can create a spaghetti plot with the command: ggplot(toy.df,aes(x=time,y=value,group=id,color=factor(id))) + geom_line() What I'd like to be able to do is jitter the lines themselves by translation so that their slopes are preserved, but so far my attempts to jitter -- within ggplot, as opposed to first jittering toy.df by hand -- seem to always jitter the two points for a given id independently, and thus change the slopes. I'd be grateful for any guidance! 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.
Re: [R] ggplot2: how to jitter spaghetti plot so slopes are preserved
Do the jittering yourself before you give the data to ggplot. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On August 20, 2014 4:56:04 PM PDT, David Romano drom...@stanford.edu wrote: Hi, Suppose I have a the data frame given by: dput(toy.df) structure(list(id = c(1, 2, 1, 2), time = c(1L, 1L, 2L, 2L), value = c(1, 2, 2, 3)), .Names = c(id, time, value), row.names = c(NA, 4L), class = data.frame) that is: toy.df id time value 1 11 1 2 21 2 3 12 2 4 22 3 I can create a spaghetti plot with the command: ggplot(toy.df,aes(x=time,y=value,group=id,color=factor(id))) + geom_line() What I'd like to be able to do is jitter the lines themselves by translation so that their slopes are preserved, but so far my attempts to jitter -- within ggplot, as opposed to first jittering toy.df by hand -- seem to always jitter the two points for a given id independently, and thus change the slopes. I'd be grateful for any guidance! 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-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] file.show() may have some bug?
Dear Rusers, when i try file.show( xxx.h) in Rstudio which using R3.0.2, it doesn't show anything. But when i use file.edit(xxx.h),it shows the right file, It is the same thing happen to xxx.c file. May you explain it to me? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU [[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-es] pregunta
Estimados Estoy entrenando hacer funciones que respondan a comandos, en esta caso en la salida gráfica se observa que dice : Exposure=var3 y outcome=var 1 quisiéramos que se reflejan los nombres de la base de datos : var1=estado, var2=cake, var3=chocolate Espero haberme explicado adecuadamente Adjunto tabla con datos #Comando que llama a una función rm(list=ls()) #setwd(D:/DEMO_new/demo_scripts/OR/) #setwd(D:/Public/Documents/R/EPICALC/funciones/OR/) data= mydata-read.csv(OR.csv,header=TRUE, sep=,, dec=.) use(data) attach(data) var1=estado var2=cake var3=chocolate library(epicalc) source(function_or.r) odratios(data,var1,var2,var3) #función odratios - function (data,var1,var2,var3){ or1 -cc(var1, var2) or2 - cc(var1, var3) } -- Nunca digas nunca, di mejor: gracias, permiso, disculpe. Este mensaje le ha llegado mediante el servicio de correo electronico que ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema Nacional de Salud. La persona que envia este correo asume el compromiso de usar el servicio a tales fines y cumplir con las regulaciones establecidas Infomed: http://www.sld.cu/ OR.csv Description: MS-Excel spreadsheet ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es
Re: [R-es] pregunta
Estimado José Betancourt Copio y pego una forma donde anda, básicamente es lo mismo pero con una pequeña diferencia, es tan parecido que están los dos códigos a continuación. Javier Marcuzzi library(epicalc) #Comando que llama a una función rm(list=ls()) #setwd(D:/DEMO_new/demo_scripts/OR/) #setwd(D:/Public/Documents/R/EPICALC/funciones/OR/) #data= mydata-read.csv(OR.csv,header=TRUE, sep=,, dec=.) data - read.csv(~/Descargas/OR.csv,header=TRUE, sep=,, dec=.) data2 - read.csv(~/Descargas/OR.csv,header=TRUE, sep=,, dec=.) use(data) attach(data) var1=estado var2=cake var3=chocolate # source(function_or.r) #función odratios - function (data,var1,var2,var3){ or1 -cc(var1, var2) or2 - cc(var1, var3) } odratios(data,var1,var2,var3) odratios2 - function (data,estado,cake,chocolate){ or1 -cc(estado, cake) or2 - cc(estado, chocolate) } odratios2(data2,estado,cake,chocolate) El 20 de agosto de 2014, 21:10, Dr. José A Betancourt Bethencourt jbetanco...@iscmc.cmw.sld.cu escribió: Estimados Estoy entrenando hacer funciones que respondan a comandos, en esta caso en la salida gráfica se observa que dice : Exposure=var3 y outcome=var 1 quisiéramos que se reflejan los nombres de la base de datos : var1=estado, var2=cake, var3=chocolate Espero haberme explicado adecuadamente Adjunto tabla con datos #Comando que llama a una función rm(list=ls()) #setwd(D:/DEMO_new/demo_scripts/OR/) #setwd(D:/Public/Documents/R/EPICALC/funciones/OR/) data= mydata-read.csv(OR.csv,header=TRUE, sep=,, dec=.) use(data) attach(data) var1=estado var2=cake var3=chocolate library(epicalc) source(function_or.r) odratios(data,var1,var2,var3) #función odratios - function (data,var1,var2,var3){ or1 -cc(var1, var2) or2 - cc(var1, var3) } ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es
Re: [R-es] pregunta
Buenas noches Javier y Jos�, Estoy en contra de usar attach(), asi que propongo la siguiente alternativa con with(): # paquete require(epicalc) # los argumentos en ... pasan de epicalc:::cc # ver ?cc para mas informacion foo - function(var1, var2, var3, ...){ or1 - cc(var1, var2, ...) or2 - cc(var1, var3, ...) list(or1 = or1, or2 = or2) } # datos x - read.csv(~/Downloads/OR.csv) head(x) # resultados SIN graficas with(x, foo(estado, cake, chocolate, graph = FALSE)) Saludos, Jorge.- 2014-08-21 12:40 GMT+10:00 Javier Marcuzzi javier.ruben.marcu...@gmail.com : Estimado Jos� Betancourt Copio y pego una forma donde anda, b�sicamente es lo mismo pero con una peque�a diferencia, es tan parecido que est�n los dos c�digos a continuaci�n. Javier Marcuzzi library(epicalc) #Comando que llama a una funci�n rm(list=ls()) #setwd(D:/DEMO_new/demo_scripts/OR/) #setwd(D:/Public/Documents/R/EPICALC/funciones/OR/) #data= mydata-read.csv(OR.csv,header=TRUE, sep=,, dec=.) data - read.csv(~/Descargas/OR.csv,header=TRUE, sep=,, dec=.) data2 - read.csv(~/Descargas/OR.csv,header=TRUE, sep=,, dec=.) use(data) attach(data) var1=estado var2=cake var3=chocolate # source(function_or.r) #funci�n odratios - function (data,var1,var2,var3){ or1 -cc(var1, var2) or2 - cc(var1, var3) } odratios(data,var1,var2,var3) odratios2 - function (data,estado,cake,chocolate){ or1 -cc(estado, cake) or2 - cc(estado, chocolate) } odratios2(data2,estado,cake,chocolate) El 20 de agosto de 2014, 21:10, Dr. Jos� A Betancourt Bethencourt jbetanco...@iscmc.cmw.sld.cu escribi�: Estimados Estoy entrenando hacer funciones que respondan a comandos, en esta caso en la salida gr�fica se observa que dice : Exposure=var3 y outcome=var 1 quisi�ramos que se reflejan los nombres de la base de datos : var1=estado, var2=cake, var3=chocolate Espero haberme explicado adecuadamente Adjunto tabla con datos #Comando que llama a una funci�n rm(list=ls()) #setwd(D:/DEMO_new/demo_scripts/OR/) #setwd(D:/Public/Documents/R/EPICALC/funciones/OR/) data= mydata-read.csv(OR.csv,header=TRUE, sep=,, dec=.) use(data) attach(data) var1=estado var2=cake var3=chocolate library(epicalc) source(function_or.r) odratios(data,var1,var2,var3) #funci�n odratios - function (data,var1,var2,var3){ or1 -cc(var1, var2) or2 - cc(var1, var3) } ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es [[alternative HTML version deleted]] ___ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es