[R] Environment variable defined in .bashrc is not recognized by R
Dear all, in my .bashrc file I have set the environment variable R_HISTFILE like this: export R_HISTFILE=$HOME/.Rhistory I then use it in my .Rprofile to have R writing all the history in a single file, rather than on a per directory basis. However this doesn't work becaus R_HISTFILE is not recognized by R. If I type: Sys.getenv(R_HISTFILE) the output is: How can I get R recognizing environment variables? Best, Luca -- Luca Cerone Skype: luca.cerone __ 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] Environment variable defined in .bashrc is not recognized by R
Luca Cerone luca.cer...@gmail.com writes: Dear all, in my .bashrc file I have set the environment variable R_HISTFILE like this: export R_HISTFILE=$HOME/.Rhistory I then use it in my .Rprofile to have R writing all the history in a single file, rather than on a per directory basis. However this doesn't work becaus R_HISTFILE is not recognized by R. Which OS? How do you start R? There is a difference between login shell (executed when you log in) and non-log in (I thik interactive shell? don't know the actual name). .baschrc is only executed after you are logged in and start the shell. So when you start R from the shell, it should work - you can check by echo $R_HISTFILE which should show you the value of the variable. If you are starting R the R gui (on Mac or RStudio) .bashrc is not sourced. Checo online for the file which will be sourced by the login shell - different between OS and distros. Cheers, Rainer If I type: Sys.getenv(R_HISTFILE) the output is: How can I get R recognizing environment variables? Best, Luca -- Rainer M. Krug email: Raineratkrugsdotde PGP: 0x0F52F982 pgpP5L0HaSJsX.pgp Description: PGP signature __ 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] Environment variable defined in .bashrc is not recognized by R
Thanks, effectively I was using RStudio (on an Ubuntu 12.04 machine). Is there any other way to make the variable available to Rstudio? Now I have simply written the path manually, but I like the idea of having a system-wide variable :) Thanks for your help, Rainer! On Tue, Apr 1, 2014 at 11:25 AM, Rainer M Krug rai...@krugs.de wrote: Luca Cerone luca.cer...@gmail.com writes: Dear all, in my .bashrc file I have set the environment variable R_HISTFILE like this: export R_HISTFILE=$HOME/.Rhistory I then use it in my .Rprofile to have R writing all the history in a single file, rather than on a per directory basis. However this doesn't work becaus R_HISTFILE is not recognized by R. Which OS? How do you start R? There is a difference between login shell (executed when you log in) and non-log in (I thik interactive shell? don't know the actual name). .baschrc is only executed after you are logged in and start the shell. So when you start R from the shell, it should work - you can check by echo $R_HISTFILE which should show you the value of the variable. If you are starting R the R gui (on Mac or RStudio) .bashrc is not sourced. Checo online for the file which will be sourced by the login shell - different between OS and distros. Cheers, Rainer If I type: Sys.getenv(R_HISTFILE) the output is: How can I get R recognizing environment variables? Best, Luca -- Rainer M. Krug email: Raineratkrugsdotde PGP: 0x0F52F982 -- Luca Cerone Tel: +34 692 06 71 28 Skype: luca.cerone __ 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] Environment variable defined in .bashrc is not recognized by R
Luca Cerone luca.cer...@gmail.com writes: Thanks, effectively I was using RStudio (on an Ubuntu 12.04 machine). Is there any other way to make the variable available to Rstudio? Now I have simply written the path manually, but I like the idea of having a system-wide variable :) Check out http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html and, specifically for Ubuntu: https://help.ubuntu.com/community/EnvironmentVariables If you need more: just google for login shell variable Ubuntu Cheers, Rainer Thanks for your help, Rainer! On Tue, Apr 1, 2014 at 11:25 AM, Rainer M Krug rai...@krugs.de wrote: Luca Cerone luca.cer...@gmail.com writes: Dear all, in my .bashrc file I have set the environment variable R_HISTFILE like this: export R_HISTFILE=$HOME/.Rhistory I then use it in my .Rprofile to have R writing all the history in a single file, rather than on a per directory basis. However this doesn't work becaus R_HISTFILE is not recognized by R. Which OS? How do you start R? There is a difference between login shell (executed when you log in) and non-log in (I thik interactive shell? don't know the actual name). .baschrc is only executed after you are logged in and start the shell. So when you start R from the shell, it should work - you can check by echo $R_HISTFILE which should show you the value of the variable. If you are starting R the R gui (on Mac or RStudio) .bashrc is not sourced. Checo online for the file which will be sourced by the login shell - different between OS and distros. Cheers, Rainer If I type: Sys.getenv(R_HISTFILE) the output is: How can I get R recognizing environment variables? Best, Luca -- Rainer M. Krug email: Raineratkrugsdotde PGP: 0x0F52F982 -- Rainer M. Krug email: Raineratkrugsdotde PGP: 0x0F52F982 pgpfplRmV0_fH.pgp Description: PGP signature __ 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] Fwd: rbind error - duplicated row.names not allowed
deleting the old rownames might help. rownames(df1) - rownames(df2) - rownames(df3) - NULL But a reproducible example would be interestng. In simple cases there is no problem with duplicated rownames as they are automatically renamed: df1 - data.frame(A=1, B=2, row.names=A) df2 - data.frame(A=1, B=2, row.names=A) rbind(df1,df2) A B A 1 2 A1 1 2 df1 - data.frame(A=1:2, B=2:3, row.names=c(A, A1)) df2 - data.frame(A=1, B=2, row.names=A) rbind(df1,df2) A B A 1 2 A1 2 3 A2 1 2 On Mon, Mar 31, 2014 at 11:53 PM, Rolf Turner r.tur...@auckland.ac.nz wrote: On 01/04/14 05:42, Jefferson Ferreira Ferreira wrote: There are other issues here addressing the same question, but I don't realize how to solve my problem based on it. So, I have 5 data frames that I want to merge rows in one unique data frame using rbind, but it returns the error: Error in row.names-.data.frame(*tmp*, value = value) : 'row.names' duplicated not allowed In addition: Warning message: non-unique values when setting 'row.names': '1', '10', '100', '1000', '1', '10', '100', '101 [] The data frames have the same columns but different number of rows. I thought the rbind command took the first column as row.names. So tried to put a sequential id in the five data frames but it doesn't work. I've tried to specify a sequential row names among the data frames via row.names() but with no success too. The merge command is not an option I think because are 5 data frames and successive merges will overwrite precedents. I've created a new data frame only with ids and tried to join but the resulting data frame don't append the columns of joined df. Follows an extract of df 1: idimage power value pol class1 1 tsx_sm_hh 0.1834515 -7.364787 hhFR2 2 tsx_sm_hh 0.1834515 -7.364787 hhFR3 3 tsx_sm_hh 0.1991938 -7.007242 hhFR4 4 tsx_sm_hh 0.1991938 -7.007242 hhFR5 5 tsx_sm_hh 0.2079365 -6.820693 hhFR6 6 tsx_sm_hh 0.2079365 -6.820693 hhFR[...]1802124 1802124 tsx_sm_hh 0.1991938 -7.007242 hhFR The four other df's are the same structure, except the 'id' columns that don't have duplicated numbers among it. 'pol' and 'image' columns are defined as levels. and all.pol - rbind(df1,df2,df3,df4,df5) return the this error of row.names duplicated. Any idea? Not without a reproducible example. If you can create one, use dput() to include the necessary data in your posting. You *might* try something like: e1 - df1[1:5,1:2] e2 - df2[1:5,1:2] ee - rbind(e1,e2) If that throws the error, include dput(e1) and dput(e2) in your posting. If it *doesn't* then this might give you some insight into just what is triggering the error. Look at rownames(df1) and rownames(df2) as well as rownames(e1) and rownames(e2). cheers, Rolf Turner __ 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] Please help! Matrices and parameter of time
Hi, Well, the solution to my problem maybe is easy, but i have really stuck with this. I have a process which evolves in three times, so there is the parameter of time (t=1,2,3).More particularly i have three 4*4 matrices, one for each time. In other words each element has three cordinates: time, row and column. The problems are these:i don't know how to express these matrices.Also i don't know how can i extract each element, for example, if i want the element from the matrix corresponding to the 3d time, the 2nd row, the 3d column, how will i extract this? I would appreciate any help and idea!Thank you!Anna S. [[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] trouble using readOGR() function
Hi all, I got some trouble trying to open a .kml file into R. Usually, the readOGR package works great for it but here I get a message error that I can't understand. When I'm typing this : myfile -readOGR(dsn=/windows/landuse.kml,layer=agricultural use) I get the following error : Error in ogrInfo(dsn = dsn, layer = layer, encoding = encoding, use_iconv = use_iconv) : Multiple incompatible geometries: 6:7 It seems that the file is read, since I get different parameters on it while using OGRSpatialRef() or ogrListLayers() Someone would have any idea to solve the incompatible geometry error ? Thanks for help! -- View this message in context: http://r.789695.n4.nabble.com/trouble-using-readOGR-function-tp4687937.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] R rms package: nomogram using imported coefficients and linear predictor
Hi , A colleague has done an Cox-regression , on data not available to me. I ran an identical Cox regression model on similar data. If I use datadist to store the distribution summaries for included variables, and replace coefficients and linear predictor with my colleague's coefficients and linear predictor, will the calculation for the nomogram be correct, or is any other information than the datadist object , coefficients and linear predictor necessary to obtain a correct nomogram? (The nomogram produced with the procedure described above seems OK.) Regards, Yngvar [[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] rpart and randomforest results
Hi all, I have a question on rpart and randomforest results: We calculated a single regression tree using rpart and got a pseudo-r2 of roundabout 10% (which is not too bad compared to a linear regression on this data). Encouraged by this we grew a whole regression forest on the same data set using randomforest. But we got pretty bad pseudo-r2 values for the randomforest (even sometimes negative values for some option settings). We then thought that if we built only one single tree with the randomforest routine we should get a result similar to that of rpart. So we set the options for randomforest to only one single tree but the resulting pseudo-r2 value was negative aswell. Does anyone have a clue as to why the randomforest results are so bad whereas the rpart result is quite ok? Is our assumption that a single tree grown by randomforest should give similar results as a tree grown by rpart wrong? What am I missing here? Thanks a lot for your help! Sonja __ 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] rpart and randomforest results
Is it possible that the random forest is somehow adjusting for optimism or overfitting? On Apr 1, 2014 7:27 AM, Schillo, Sonja sonja.schi...@uni-due.de wrote: Hi all, I have a question on rpart and randomforest results: We calculated a single regression tree using rpart and got a pseudo-r2 of roundabout 10% (which is not too bad compared to a linear regression on this data). Encouraged by this we grew a whole regression forest on the same data set using randomforest. But we got pretty bad pseudo-r2 values for the randomforest (even sometimes negative values for some option settings). We then thought that if we built only one single tree with the randomforest routine we should get a result similar to that of rpart. So we set the options for randomforest to only one single tree but the resulting pseudo-r2 value was negative aswell. Does anyone have a clue as to why the randomforest results are so bad whereas the rpart result is quite ok? Is our assumption that a single tree grown by randomforest should give similar results as a tree grown by rpart wrong? What am I missing here? Thanks a lot for your help! Sonja __ 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] colors in violin plot, ggplot2
Hi Denis, Thank you so much. This is exactly what i needed. I am not telling you how much time i wasted to change default colors for fill and colour, coming up with pretty weird ideas, non working, of course. Thanks again, Monica Date: Tue, 1 Apr 2014 02:23:08 -0700 Subject: Re: [R] colors in violin plot, ggplot2 From: djmu...@gmail.com To: pisican...@hotmail.com Hi: Your example is not reproducible in the absence of data, but this is an opportunity to show you how to make one. I'm using the built-in mtcars data set for illustration. Assuming that all you want is to change the default color/fill scheme, here's one way to do it. library(ggplot2) mtcars1 - mtcars# make a copy of mtcars # Change cyl from numeric to factor mtcars1$cyl - factor(mtcars1$cyl) ggplot(mtcars1, aes(x = cyl, y = mpg, fill = cyl, colour = cyl)) + geom_violin(alpha=0.3, width=1, trim = FALSE, scale = width, adjust = 0.5) + geom_boxplot(width=0.2, outlier.colour=red, notch = FALSE, notchwidth = .5, alpha = 0.5, colour = grey50) + scale_colour_manual(values = c(orange, brown, forestgreen)) + scale_fill_manual(values = c(orange, brown, forestgreen)) Dennis On Mon, Mar 31, 2014 at 7:43 PM, Monica Pisica pisican...@hotmail.com wrote: Hi, I am using ggplot and geom_violin to build a violin plot of some with only 2 categories. All is good except that I cannot set up the colors I want or the violin plots. Either I have same color for both my categories or colors from probably rainbow(2), which are red and blue. What if I want brown and forestgreen. How do I do it? so my code follows: p - ggplot(x1, aes(Location, aer_m_GPS , fill=factor(Location), colour=factor(Location))) p1 - p+geom_violin(alpha=0.3, width=1, trim = FALSE, scale = width, adjust = 0.5) + geom_boxplot(width=0.2, outlier.colour=red, notch = FALSE, notchwidth = .5, alpha = 0.5, colour = grey50) p1 This will plot the violin plot with boxplot superimposed on it, both with color red and blue. I hope to get brown and forestgreen. Thanks for any advice, Monica __ 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] A vector of normal distributed values with a sum-to-zero constraint
Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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 vector of normal distributed values with a sum-to-zero constraint
You are on a fool's errand. Read FAQ 7.31. --- 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 April 1, 2014 5:56:24 AM PDT, Marc Marí Dell'Olmo marceivi...@gmail.com wrote: Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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] Please help! Matrices and parameter of time
Use an 3-dimensional array. ?array And any basic introduction to R. - David L Carlson Department of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ANNA SIMEONIDOU Sent: Tuesday, April 1, 2014 3:37 AM To: r-help@r-project.org Subject: [R] Please help! Matrices and parameter of time Hi, Well, the solution to my problem maybe is easy, but i have really stuck with this. I have a process which evolves in three times, so there is the parameter of time (t=1,2,3).More particularly i have three 4*4 matrices, one for each time. In other words each element has three cordinates: time, row and column. The problems are these:i don't know how to express these matrices.Also i don't know how can i extract each element, for example, if i want the element from the matrix corresponding to the 3d time, the 2nd row, the 3d column, how will i extract this? I would appreciate any help and idea!Thank you!Anna S. [[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] Please help! Matrices and parameter of time
This mailing list has a no homework policy (read the Posting Guide, please, which also requests that you post in plain text format only). If this is not homework then you will have to be a bit more specific about what you know and what you don't in order to get useful help. Questions about why you should put certain values in particular locations in your array are not about R and are off topic here. If you are having difficulty with R syntax for arrays, I recommend reading the Introduction to R document supplied with the software, and experimenting. If you are still having difficulty after doing that, then refer to where you get lost in that document when asking for more help. A word of advice: the least obvious thing about arrays to beginners is that they are constructed using one big vector rather than a bunch of little vectors, yet it is possible to extract or change little vectors or arrays from the larger array using indexing. --- 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 April 1, 2014 1:37:14 AM PDT, ANNA SIMEONIDOU assyme...@hotmail.com wrote: Hi, Well, the solution to my problem maybe is easy, but i have really stuck with this. I have a process which evolves in three times, so there is the parameter of time (t=1,2,3).More particularly i have three 4*4 matrices, one for each time. In other words each element has three cordinates: time, row and column. The problems are these:i don't know how to express these matrices.Also i don't know how can i extract each element, for example, if i want the element from the matrix corresponding to the 3d time, the 2nd row, the 3d column, how will i extract this? I would appreciate any help and idea!Thank you!Anna S. [[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] A vector of normal distributed values with a sum-to-zero constraint
Make a copy with opposite sign. This is Normal, symmetric, but no longer random. set.seed(112358) x - rnorm(5000, 0, 0.5) x - c(x, -x) sum(x) hist(x) B. On 2014-04-01, at 8:56 AM, Marc Marí Dell'Olmo wrote: Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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] A vector of normal distributed values with a sum-to-zero constraint
The sum-to-zero constraint imposes a loss of one degree of freedom. Of N samples, only (N-1) can be random. Thus the solution is N - 100 x - rnorm(N-1) x - c(x, -sum(x)) sum(x) [1] -7.199102e-17 Boris Steipe boris.ste...@utoronto.ca Sent by: r-help-boun...@r-project.org 04/01/2014 09:29 AM To Marc Marí Dell'Olmo marceivi...@gmail.com, cc r-help@r-project.org r-help@r-project.org Subject Re: [R] A vector of normal distributed values with a sum-to-zero constraint Make a copy with opposite sign. This is Normal, symmetric, but no longer random. set.seed(112358) x - rnorm(5000, 0, 0.5) x - c(x, -x) sum(x) hist(x) B. On 2014-04-01, at 8:56 AM, Marc Marí Dell'Olmo wrote: Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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. [[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] A vector of normal distributed values with a sum-to-zero constraint
But the result is not Normal. Consider: set.seed(112358) N - 100 x - rnorm(N-1) sum(x) [1] 1.759446 !!! i.e. you have an outlier at 1.7 sigma, and for larger N... set.seed(112358) N - 1 x - rnorm(N-1) sum(x) [1] -91.19731 B. On 2014-04-01, at 10:14 AM, jlu...@ria.buffalo.edu wrote: The sum-to-zero constraint imposes a loss of one degree of freedom. Of N samples, only (N-1) can be random. Thus the solution is N - 100 x - rnorm(N-1) x - c(x, -sum(x)) sum(x) [1] -7.199102e-17 Boris Steipe boris.ste...@utoronto.ca Sent by: r-help-boun...@r-project.org 04/01/2014 09:29 AM To Marc Marí Dell'Olmo marceivi...@gmail.com, cc r-help@r-project.org r-help@r-project.org Subject Re: [R] A vector of normal distributed values with a sum-to-zero constraint Make a copy with opposite sign. This is Normal, symmetric, but no longer random. set.seed(112358) x - rnorm(5000, 0, 0.5) x - c(x, -x) sum(x) hist(x) B. On 2014-04-01, at 8:56 AM, Marc Marí Dell'Olmo wrote: Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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-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 vector of normal distributed values with a sum-to-zero constraint
Boris is right. I need this vector to include as initial values of a MCMC process (with openbugs) and If I use this last approach sum(x) could be a large (or extreme) value and can cause problems. The other approach x - c(x, -x) has the problem that only vectors with even values are obtained. Thank you! 2014-04-01 16:25 GMT+02:00 Boris Steipe boris.ste...@utoronto.ca: But the result is not Normal. Consider: set.seed(112358) N - 100 x - rnorm(N-1) sum(x) [1] 1.759446 !!! i.e. you have an outlier at 1.7 sigma, and for larger N... set.seed(112358) N - 1 x - rnorm(N-1) sum(x) [1] -91.19731 B. On 2014-04-01, at 10:14 AM, jlu...@ria.buffalo.edu wrote: The sum-to-zero constraint imposes a loss of one degree of freedom. Of N samples, only (N-1) can be random. Thus the solution is N - 100 x - rnorm(N-1) x - c(x, -sum(x)) sum(x) [1] -7.199102e-17 Boris Steipe boris.ste...@utoronto.ca Sent by: r-help-boun...@r-project.org 04/01/2014 09:29 AM To Marc Marí Dell'Olmo marceivi...@gmail.com, cc r-help@r-project.org r-help@r-project.org Subject Re: [R] A vector of normal distributed values with a sum-to-zero constraint Make a copy with opposite sign. This is Normal, symmetric, but no longer random. set.seed(112358) x - rnorm(5000, 0, 0.5) x - c(x, -x) sum(x) hist(x) B. On 2014-04-01, at 8:56 AM, Marc Marí Dell'Olmo wrote: Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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-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] A vector of normal distributed values with a sum-to-zero constraint
It seems so simple to me, that I must be missing something. Subject to Jeff Newmiller's reminder of FAQ 7.31; if the sum is zero then the mean is zero and vice versa. The OP's original attempt of: - l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) - is equivalent to aux2 - rnorm(l,0,0.5) aux2 - aux2-mean(aux2) If calculations were exact then aux2 would have mean, and thus sum, equal to zero - any difference from zero is attributable entirely to machine precision. On 01/04/2014 15:25, Boris Steipe wrote: But the result is not Normal. Consider: set.seed(112358) N - 100 x - rnorm(N-1) sum(x) [1] 1.759446 !!! i.e. you have an outlier at 1.7 sigma, and for larger N... set.seed(112358) N - 1 x - rnorm(N-1) sum(x) [1] -91.19731 B. On 2014-04-01, at 10:14 AM, jlu...@ria.buffalo.edu wrote: The sum-to-zero constraint imposes a loss of one degree of freedom. Of N samples, only (N-1) can be random. Thus the solution is N - 100 x - rnorm(N-1) x - c(x, -sum(x)) sum(x) [1] -7.199102e-17 Boris Steipe boris.ste...@utoronto.ca Sent by: r-help-boun...@r-project.org 04/01/2014 09:29 AM To Marc Marí Dell'Olmo marceivi...@gmail.com, cc r-help@r-project.org r-help@r-project.org Subject Re: [R] A vector of normal distributed values with a sum-to-zero constraint Make a copy with opposite sign. This is Normal, symmetric, but no longer random. set.seed(112358) x - rnorm(5000, 0, 0.5) x - c(x, -x) sum(x) hist(x) B. On 2014-04-01, at 8:56 AM, Marc Marí Dell'Olmo wrote: Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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-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 vector of normal distributed values with a sum-to-zero constraint
Then what's wrong with centering your initial values around the mean? Marc Marí Dell'Olmo marceivi...@gmail.com 04/01/2014 10:56 AM To Boris Steipe boris.ste...@utoronto.ca, cc jlu...@ria.buffalo.edu, r-help@r-project.org r-help@r-project.org Subject Re: [R] A vector of normal distributed values with a sum-to-zero constraint Boris is right. I need this vector to include as initial values of a MCMC process (with openbugs) and If I use this last approach sum(x) could be a large (or extreme) value and can cause problems. The other approach x - c(x, -x) has the problem that only vectors with even values are obtained. Thank you! 2014-04-01 16:25 GMT+02:00 Boris Steipe boris.ste...@utoronto.ca: But the result is not Normal. Consider: set.seed(112358) N - 100 x - rnorm(N-1) sum(x) [1] 1.759446 !!! i.e. you have an outlier at 1.7 sigma, and for larger N... set.seed(112358) N - 1 x - rnorm(N-1) sum(x) [1] -91.19731 B. On 2014-04-01, at 10:14 AM, jlu...@ria.buffalo.edu wrote: The sum-to-zero constraint imposes a loss of one degree of freedom. Of N samples, only (N-1) can be random. Thus the solution is N - 100 x - rnorm(N-1) x - c(x, -sum(x)) sum(x) [1] -7.199102e-17 Boris Steipe boris.ste...@utoronto.ca Sent by: r-help-boun...@r-project.org 04/01/2014 09:29 AM To Marc Marí Dell'Olmo marceivi...@gmail.com, cc r-help@r-project.org r-help@r-project.org Subject Re: [R] A vector of normal distributed values with a sum-to-zero constraint Make a copy with opposite sign. This is Normal, symmetric, but no longer random. set.seed(112358) x - rnorm(5000, 0, 0.5) x - c(x, -x) sum(x) hist(x) B. On 2014-04-01, at 8:56 AM, Marc Marí Dell'Olmo wrote: Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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-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] A vector of normal distributed values with a sum-to-zero constraint
Hello, One way is to use ?scale. set.seed(4867) l - 100 aux - rnorm(l, 0, 0.5) aux - scale(aux, scale = FALSE) sum(aux) hist(aux, prob = TRUE) curve(dnorm(x, 0, 0.5), from = -2, to = 2, add = TRUE) Hope this helps, Rui Barradas Em 01-04-2014 16:01, jlu...@ria.buffalo.edu escreveu: Then what's wrong with centering your initial values around the mean? Marc Marí Dell'Olmo marceivi...@gmail.com 04/01/2014 10:56 AM To Boris Steipe boris.ste...@utoronto.ca, cc jlu...@ria.buffalo.edu, r-help@r-project.org r-help@r-project.org Subject Re: [R] A vector of normal distributed values with a sum-to-zero constraint Boris is right. I need this vector to include as initial values of a MCMC process (with openbugs) and If I use this last approach sum(x) could be a large (or extreme) value and can cause problems. The other approach x - c(x, -x) has the problem that only vectors with even values are obtained. Thank you! 2014-04-01 16:25 GMT+02:00 Boris Steipe boris.ste...@utoronto.ca: But the result is not Normal. Consider: set.seed(112358) N - 100 x - rnorm(N-1) sum(x) [1] 1.759446 !!! i.e. you have an outlier at 1.7 sigma, and for larger N... set.seed(112358) N - 1 x - rnorm(N-1) sum(x) [1] -91.19731 B. On 2014-04-01, at 10:14 AM, jlu...@ria.buffalo.edu wrote: The sum-to-zero constraint imposes a loss of one degree of freedom. Of N samples, only (N-1) can be random. Thus the solution is N - 100 x - rnorm(N-1) x - c(x, -sum(x)) sum(x) [1] -7.199102e-17 Boris Steipe boris.ste...@utoronto.ca Sent by: r-help-boun...@r-project.org 04/01/2014 09:29 AM To Marc Marí Dell'Olmo marceivi...@gmail.com, cc r-help@r-project.org r-help@r-project.org Subject Re: [R] A vector of normal distributed values with a sum-to-zero constraint Make a copy with opposite sign. This is Normal, symmetric, but no longer random. set.seed(112358) x - rnorm(5000, 0, 0.5) x - c(x, -x) sum(x) hist(x) B. On 2014-04-01, at 8:56 AM, Marc Marí Dell'Olmo wrote: Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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-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-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] importing multiple text files in R
Dear useRs, I have a number of text file located at a certain location with the following names. s1.txt,s2.txt,s3.txt,s4.txt,s5.txt...s120.txt when i read them, before opening them, by using filelist = list.files(pattern = .s*.txt) The are opened in the following order [1] s1.txt s10.txt s100.txt s101.txt s102.txt s103.txt s104.txt s105.txt s106.txt s107.txt s108.txt s109.txt s11.txt s110.txt [15] s111.txt s112.txt s113.txt s114.txt s115.txt s116.txt s117.txt s118.txt s119.txt s12.txt s120.txt s13.txt s14.txt s15.txt [29] s16.txt s17.txt s18.txt s19.txt s2.txt s20.txt s21.txt s22.txt s23.txt s24.txt s25.txt s26.txt s27.txt s28.txt [43] s29.txt s3.txt s30.txt s31.txt s32.txt s33.txt s34.txt s35.txt s36.txt s37.txt s38.txt s39.txt s4.txt s40.txt [57] s41.txt s42.txt s43.txt s44.txt s45.txt s46.txt s47.txt s48.txt s49.txt s5.txt s50.txt s51.txt s52.txt s53.txt [71] s54.txt s55.txt s56.txt s57.txt s58.txt s59.txt s6.txt s60.txt s61.txt s62.txt s63.txt s64.txt s65.txt s66.txt [85] s67.txt s68.txt s69.txt s7.txt s70.txt s71.txt s72.txt s73.txt s74.txt s75.txt s76.txt s77.txt s78.txt s79.txt [99] s8.txt s80.txt s81.txt s82.txt s83.txt s84.txt s85.txt s86.txt s87.txt s88.txt s89.txt s9.txt s90.txt s91.txt [113] s92.txt s93.txt s94.txt s95.txt s96.txt s97.txt s98.txt s99.txt How can I open them systematically starting from s1,s2,s3 and all the way upto s120? Thankyou very much indeed in advance. Eliza [[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] Remove part of a summary of a model in a regression output
I would like to drop the out put part of the output that begins with as.factor(stratadow) in the summary of a model shown below.How can I accomplish this task? Thanks summary(mod1) Family: poisson Link function: log Formula: death ~ hw + temp + as.factor(stratadow) Parametric coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 1.4502766 0.3855373 3.762 0.000169 *** hw 0.0528747 0.1387688 0.381 0.703183 temp -0.0010948 0.0209806 -0.052 0.958382 as.factor(stratadow)1101 0.1240602 0.3351163 0.370 0.711233 as.factor(stratadow)1102 0.1226159 0.3352892 0.366 0.714588 as.factor(stratadow)1103 0.2711197 0.3246650 0.835 0.403675 as.factor(stratadow)1104 0.1746700 0.3309611 0.528 0.597662 as.factor(stratadow)1105 0.0677140 0.3407435 0.199 0.842478 as.factor(stratadow)1106 -0.0011192 0.3436671 -0.003 0.997402 as.factor(stratadow)1360 0.0117679 0.3441415 0.034 0.972722 as.factor(stratadow)1361 -0.0489304 0.3494791 -0.140 0.888652 as.factor(stratadow)1362 0.1235263 0.3349138 0.369 0.712254 [[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] importing multiple text files in R
Try mixedsort in gtools package Br. Frede Sendt fra Samsung mobil Oprindelig meddelelse Fra: eliza botto Dato:01/04/2014 18.10 (GMT+01:00) Til: r-help@r-project.org Emne: [R] importing multiple text files in R Dear useRs, I have a number of text file located at a certain location with the following names. s1.txt,s2.txt,s3.txt,s4.txt,s5.txt...s120.txt when i read them, before opening them, by using filelist = list.files(pattern = .s*.txt) The are opened in the following order [1] s1.txt s10.txt s100.txt s101.txt s102.txt s103.txt s104.txt s105.txt s106.txt s107.txt s108.txt s109.txt s11.txt s110.txt [15] s111.txt s112.txt s113.txt s114.txt s115.txt s116.txt s117.txt s118.txt s119.txt s12.txt s120.txt s13.txt s14.txt s15.txt [29] s16.txt s17.txt s18.txt s19.txt s2.txt s20.txt s21.txt s22.txt s23.txt s24.txt s25.txt s26.txt s27.txt s28.txt [43] s29.txt s3.txt s30.txt s31.txt s32.txt s33.txt s34.txt s35.txt s36.txt s37.txt s38.txt s39.txt s4.txt s40.txt [57] s41.txt s42.txt s43.txt s44.txt s45.txt s46.txt s47.txt s48.txt s49.txt s5.txt s50.txt s51.txt s52.txt s53.txt [71] s54.txt s55.txt s56.txt s57.txt s58.txt s59.txt s6.txt s60.txt s61.txt s62.txt s63.txt s64.txt s65.txt s66.txt [85] s67.txt s68.txt s69.txt s7.txt s70.txt s71.txt s72.txt s73.txt s74.txt s75.txt s76.txt s77.txt s78.txt s79.txt [99] s8.txt s80.txt s81.txt s82.txt s83.txt s84.txt s85.txt s86.txt s87.txt s88.txt s89.txt s9.txt s90.txt s91.txt [113] s92.txt s93.txt s94.txt s95.txt s96.txt s97.txt s98.txt s99.txt How can I open them systematically starting from s1,s2,s3 and all the way upto s120? Thankyou very much indeed in advance. Eliza [[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.
[R] Times and Dates
Is the time and date package the right one to convert a vector, such as the following, into a time format? 12:06 11:51 11:53 12:27 14:20 12:27 The aim is to deal with a time variable numerically (find means, etc). Thanks Harold [[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] jointprior in deal package
someone has solved the problem?? I have the same problem [[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] Plotting Satellite
I want to read the following file with and extract the longitude and latitude for certain areas. The file is satellite data from topex and contains the monthly wave energy fluxes around the worlds oceans. For doing that i have the following loop that reads the specific data. I then want to create a worldmap/the specific region for example the baltic sea or whatever, that shows the the wave energy. Also i want to plot the averages and the trend for the wave energy and eventually calcualte a slope for the wave energy over time. I got the following loop library(sp) library(maptools) library(maps) library(rgdal) library(shape) library(mapdata) # pow_sat_file.txt inputpath1-/Users/Sam/Desktop/MER/rem/ inputfile1-paste(inputpath1,pow_sat_file.txt,sep=) sat-read.table(pow_sat_file.txt,header=TRUE, sep=,nrow=-1) sat.mat-as.data.frame(sat) dims-dim(sat.mat) tempo-matrix(0, nrow=dims[1], ncol=dims[2]) tempo-data.frame(tempo) date-seq(as.Date(1993/1/1), as.Date(2005/10/1), by=month) # France coordinates long.min--6 long.max-10 lat.min-40 lat.max-52 #Loop on pow_sat_file.txt to only keep the interesting points for (i in 1:dims[1]){ long-sat.mat[i,1] lat-sat.mat[i,2] if (((long=-6 long=10)==TRUE ) ((lat=40 lat=52))==TRUE){ tempo[i,1]-long tempo[i,2]-lat for (j in 3:dims[2]){ tempo[i,j]-sat.mat[i,j] } } } How do i continue from here to get a map of the specific region and a slope? Thx in advance -- View this message in context: http://r.789695.n4.nabble.com/Plotting-Satellite-tp4687971.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] Times and Dates
On 01/04/2014 12:33 PM, Doran, Harold wrote: Is the time and date package the right one to convert a vector, such as the following, into a time format? 12:06 11:51 11:53 12:27 14:20 12:27 The aim is to deal with a time variable numerically (find means, etc). I don't know which package you were referring to. You can convert strings to POSIXlt objects using the base package strptime function. Those aren't numbers, but if you further convert them to POSIXct objects, they are. The mean() function works on either type. For example, x - strptime( c(12:06, 11:51) , format=%H:%M) x [1] 2014-04-01 12:06:00 EDT 2014-04-01 11:51:00 EDT mean(x) [1] 2014-04-01 11:58:30 EDT You may get different results for the day and time zone. If you don't want to see those, format the output: format(mean(x), format=%H:%M) [1] 11:58 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] importing multiple text files in R
you can extract numbers from your file names and then sort them like this: filelist = list.files(pattern = .s*.txt) filelist[order(as.integer(gsub([^0-9], , filelist)))] (cf with alphabetic order: filelist[order(gsub([^0-9], , filelist))] Or if you just have s1...s120 you can construct the names programmatically filelist-paste0(s, 1:120, .txt) On Tue, Apr 1, 2014 at 7:19 PM, Frede Aakmann Tøgersen fr...@vestas.com wrote: Try mixedsort in gtools package Br. Frede Sendt fra Samsung mobil Oprindelig meddelelse Fra: eliza botto Dato:01/04/2014 18.10 (GMT+01:00) Til: r-help@r-project.org Emne: [R] importing multiple text files in R Dear useRs, I have a number of text file located at a certain location with the following names. s1.txt,s2.txt,s3.txt,s4.txt,s5.txt...s120.txt when i read them, before opening them, by using filelist = list.files(pattern = .s*.txt) The are opened in the following order [1] s1.txt s10.txt s100.txt s101.txt s102.txt s103.txt s104.txt s105.txt s106.txt s107.txt s108.txt s109.txt s11.txt s110.txt [15] s111.txt s112.txt s113.txt s114.txt s115.txt s116.txt s117.txt s118.txt s119.txt s12.txt s120.txt s13.txt s14.txt s15.txt [29] s16.txt s17.txt s18.txt s19.txt s2.txt s20.txt s21.txt s22.txt s23.txt s24.txt s25.txt s26.txt s27.txt s28.txt [43] s29.txt s3.txt s30.txt s31.txt s32.txt s33.txt s34.txt s35.txt s36.txt s37.txt s38.txt s39.txt s4.txt s40.txt [57] s41.txt s42.txt s43.txt s44.txt s45.txt s46.txt s47.txt s48.txt s49.txt s5.txt s50.txt s51.txt s52.txt s53.txt [71] s54.txt s55.txt s56.txt s57.txt s58.txt s59.txt s6.txt s60.txt s61.txt s62.txt s63.txt s64.txt s65.txt s66.txt [85] s67.txt s68.txt s69.txt s7.txt s70.txt s71.txt s72.txt s73.txt s74.txt s75.txt s76.txt s77.txt s78.txt s79.txt [99] s8.txt s80.txt s81.txt s82.txt s83.txt s84.txt s85.txt s86.txt s87.txt s88.txt s89.txt s9.txt s90.txt s91.txt [113] s92.txt s93.txt s94.txt s95.txt s96.txt s97.txt s98.txt s99.txt How can I open them systematically starting from s1,s2,s3 and all the way upto s120? Thankyou very much indeed in advance. Eliza [[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. __ 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] Environment variable defined in .bashrc is not recognized by R
Use .Renviron Hadley On Tue, Apr 1, 2014 at 2:33 AM, Luca Cerone luca.cer...@gmail.com wrote: Thanks, effectively I was using RStudio (on an Ubuntu 12.04 machine). Is there any other way to make the variable available to Rstudio? Now I have simply written the path manually, but I like the idea of having a system-wide variable :) Thanks for your help, Rainer! On Tue, Apr 1, 2014 at 11:25 AM, Rainer M Krug rai...@krugs.de wrote: Luca Cerone luca.cer...@gmail.com writes: Dear all, in my .bashrc file I have set the environment variable R_HISTFILE like this: export R_HISTFILE=$HOME/.Rhistory I then use it in my .Rprofile to have R writing all the history in a single file, rather than on a per directory basis. However this doesn't work becaus R_HISTFILE is not recognized by R. Which OS? How do you start R? There is a difference between login shell (executed when you log in) and non-log in (I thik interactive shell? don't know the actual name). .baschrc is only executed after you are logged in and start the shell. So when you start R from the shell, it should work - you can check by echo $R_HISTFILE which should show you the value of the variable. If you are starting R the R gui (on Mac or RStudio) .bashrc is not sourced. Checo online for the file which will be sourced by the login shell - different between OS and distros. Cheers, Rainer If I type: Sys.getenv(R_HISTFILE) the output is: How can I get R recognizing environment variables? Best, Luca -- Rainer M. Krug email: Raineratkrugsdotde PGP: 0x0F52F982 -- Luca Cerone Tel: +34 692 06 71 28 Skype: luca.cerone __ 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. -- http://had.co.nz/ __ 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] Remove part of a summary of a model in a regression output
Hi, You could extract the part you wanted by: indx - grepl(as.factor,names(mod1$coefficients)) coef(summary(mod1))[!indx,] A.K. On Tuesday, April 1, 2014 1:03 PM, Kumsa waddee...@gmail.com wrote: I would like to drop the out put part of the output that begins with as.factor(stratadow) in the summary of a model shown below.How can I accomplish this task? Thanks summary(mod1) Family: poisson Link function: log Formula: death ~ hw + temp + as.factor(stratadow) Parametric coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 1.4502766 0.3855373 3.762 0.000169 *** hw 0.0528747 0.1387688 0.381 0.703183 temp -0.0010948 0.0209806 -0.052 0.958382 as.factor(stratadow)1101 0.1240602 0.3351163 0.370 0.711233 as.factor(stratadow)1102 0.1226159 0.3352892 0.366 0.714588 as.factor(stratadow)1103 0.2711197 0.3246650 0.835 0.403675 as.factor(stratadow)1104 0.1746700 0.3309611 0.528 0.597662 as.factor(stratadow)1105 0.0677140 0.3407435 0.199 0.842478 as.factor(stratadow)1106 -0.0011192 0.3436671 -0.003 0.997402 as.factor(stratadow)1360 0.0117679 0.3441415 0.034 0.972722 as.factor(stratadow)1361 -0.0489304 0.3494791 -0.140 0.888652 as.factor(stratadow)1362 0.1235263 0.3349138 0.369 0.712254 [[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] A vector of normal distributed values with a sum-to-zero constraint
Here is one approach to generating a set (or in this case multiple sets) of normals that sum to 0 (with a little round off error) and works for an odd number of points: v - matrix(-1/8, 9, 9) diag(v) - 1 eigen(v) x - mvrnorm(100,mu=rep(0,9), Sigma=v, empirical=TRUE) rowSums(x) range(.Last.value) hist(x) sd(x) mean(x) apply(x,2,sd) the key is to find the value of the off diagonals in the covariance matrix that gives you exactly one eigenvalue that is equal to 0 (or close enough with rounding) and all the others are positive. There is probably a mathematical formula that gives the exact value to use, but I found one that works with a little trial and error (it will change for different sample sizes). On Tue, Apr 1, 2014 at 6:56 AM, Marc Marí Dell'Olmo marceivi...@gmail.com wrote: Dear all, Anyone knows how to generate a vector of Normal distributed values (for example N(0,0.5)), but with a sum-to-zero constraint?? The sum would be exactly zero, without decimals. I made some attempts: l - 100 aux - rnorm(l,0,0.5) s - sum(aux)/l aux2 - aux-s sum(aux2) [1] -0.0006131392 aux[1]- -sum(aux[2:l]) sum(aux) [1] -0.03530422 but the sum is not exactly zero and not all parameters are N(0,0.5) distributed... Perhaps is obvious but I can't find the way to do it.. Thank you very much! Marc __ 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. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.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] Create sequential vector for values in another column
Hi, May be this helps: set.seed(14) dat1 - data.frame(shell_ID= sample(c(0208A_47_33,0208A_47_34,0912C_13_3,1400C_2_48),20,replace=TRUE),stringsAsFactors=FALSE) dat2 - dat1 ord1 - order(as.numeric(gsub([[:alpha:]]+.*,,dat1$shell_ID)),as.numeric(gsub(.*\\_,,dat1$shell_ID)) ) dat1 - dat1[ord1,,drop=FALSE] row.names(dat1) - 1:nrow(dat1) #or library(gtools) dat2$shell_ID - mixedsort(dat2$shell_ID) identical(dat1,dat2) #[1] TRUE dat1$x - as.numeric(factor(dat1$shell_ID)) dat1 #or dat2$x - match(dat1$shell_ID,unique(dat1$shell_ID)) all.equal(dat1,dat2) #[1] TRUE A.K. Hi all, I am trying to do a similar thing however I would like the second vector to read as follows. shell_ID X 0208A_47_33 1 0208A_47_33 1 0208A_47_33 1 0208A_47_34 2 0208A_47_34 2 0208A_47_34 2 0208A_47_34 2 0208A_47_34 2 0208A_47_34 2 0208A_47_34 2 0912C_13_3 3 0912C_13_3 3 0912C_13_3 3 1400C_2_48 4 1400C_2_48 4 1400C_2_48 4 1400C_2_48 4 1400C_2_48 4 1400C_2_48 4 1400C_2_48 4 1400C_2_48 4 1400C_2_48 4 However the shell_ID's may not be in any particular order as I am already using a subset of data based on another variable in R I am not familiar with how to check that the shell_IDs are sorted. The subset contains 21,005 unique shell_ID's. Thanks Helen __ 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] Char to Numeric --- Type Conversion
Hi, May be this helps: set.seed(445) dat1 - as.data.frame(matrix(sample(seq(2,4,by=0.5),80,replace=TRUE),ncol=20),stringsAsFactors=FALSE) dat1[dat1==2] - dat1[,sapply(dat1,is.character)] - lapply(dat1[,sapply(dat1,is.character)] ,as.numeric) identical(sum(sapply(dat1,is.numeric)), ncol(dat1)) #[1] TRUE A.K. Hi All, I have a dataframe with 100 columns. In some of the columns, the values are of type CHAR. I wanted to do type conversion for the whole table, wherever I find the values to be char into Num. Regards, Praveen __ 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] 127.0.0.1:22381/doc/html/index.html won't start
Dear All, Sorry to bother you. I am using Aquamacs 3.0a (GNU Emacs 24.3.50.2), newly installed. Somehow, on my mac even the newly installed R3.0.3 will mill endlessly after M-x R waiting for 127.0.0.1:22381/doc/html/index.html to load. How can I find out, what is wrong with my configuration? Thanks for considering. Christian __ 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] 127.0.0.1:22381/doc/html/index.html won't start 2.
Dear All, Sorry to bother you. I am using Aquamacs 3.0a (GNU Emacs 24.3.50.2), newly installed, on Mac OSX 10.7.5 . Somehow, on my mac even the newly installed R3.0.3 will mill endlessly after M-x R waiting for 127.0.0.1:22381/doc/html/index.html to load. How can I find out, what is wrong with my configuration? Thanks for considering. Christian __ 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] Plotting Satellite
Hi, What are the columns in sat.mat? I can see that, sat.mat[,1:2] are longitude and latitude in some form but we don't even know what dim(sat.mat)[2] is from what you've shown. You can avoid the loops (untested): asub - sat.mat[,1] = long.min sat.mat[,1] = long.max sat.mat[,2] = lat.min sat.mat[,2] = lat.max tempo - sat.mat[asub, ] Note that you don't need to equate to TRUE, and is vectorized. Your process would have needed to zap out rows with values of zero in tempo[,1:2] but since your longitude range straddles longitude 0 you might have a problem there. ## basic plot plot(tempo[,1:2], pch = .) Using other columns you can control the plot colours and symbols, and there is higher-level support for these idioms in the packages you load but haven't use. Check out R-Sig-Geo in future as a list relevant to this topic. When posting include examples relevant only to your question, and recreate or point to example data. Are the data gridded? If so I'd be going to the provider for a sensible format and avoid this raw table thing completely. If you can't get that use the tools in the Spatial suite to sort it out and streamline first. Cheers, Mike. On Wed, Apr 2, 2014 at 4:23 AM, Dao_De z...@gmx.de wrote: I want to read the following file with and extract the longitude and latitude for certain areas. The file is satellite data from topex and contains the monthly wave energy fluxes around the worlds oceans. For doing that i have the following loop that reads the specific data. I then want to create a worldmap/the specific region for example the baltic sea or whatever, that shows the the wave energy. Also i want to plot the averages and the trend for the wave energy and eventually calcualte a slope for the wave energy over time. I got the following loop library(sp) library(maptools) library(maps) library(rgdal) library(shape) library(mapdata) # pow_sat_file.txt inputpath1-/Users/Sam/Desktop/MER/rem/ inputfile1-paste(inputpath1,pow_sat_file.txt,sep=) sat-read.table(pow_sat_file.txt,header=TRUE, sep=,nrow=-1) sat.mat-as.data.frame(sat) dims-dim(sat.mat) tempo-matrix(0, nrow=dims[1], ncol=dims[2]) tempo-data.frame(tempo) date-seq(as.Date(1993/1/1), as.Date(2005/10/1), by=month) # France coordinates long.min--6 long.max-10 lat.min-40 lat.max-52 #Loop on pow_sat_file.txt to only keep the interesting points for (i in 1:dims[1]){ long-sat.mat[i,1] lat-sat.mat[i,2] if (((long=-6 long=10)==TRUE ) ((lat=40 lat=52))==TRUE){ tempo[i,1]-long tempo[i,2]-lat for (j in 3:dims[2]){ tempo[i,j]-sat.mat[i,j] } } } How do i continue from here to get a map of the specific region and a slope? Thx in advance -- View this message in context: http://r.789695.n4.nabble.com/Plotting-Satellite-tp4687971.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. -- Michael Sumner Software and Database Engineer Australian Antarctic Division Hobart, Australia e-mail: mdsum...@gmail.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] Plotting Satellite
sorry i forgot to put the file; Here it is https://www.dropbox.com/s/paau32l6bth5t8r/pow_sat_file.txt -- View this message in context: http://r.789695.n4.nabble.com/Plotting-Satellite-tp4687971p4687981.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] MULTIPLE LEVELS for a SINGLE VALUE in a dataframe, how do I remove these?
I have a series of dates and times in one column. They are all in the format %m/%d/%Y %H:%M:%S; however, they are character values. I have a number of problems: 1) if I use antdist$ts[1] to just examine the FIRST value of the timestamp (ts) column, it shows that there are 144873 Levels, and it should only have 1 Level with the first value of 6/1/2013 08:07:39; how do I delete the remaining levels? 2) I need to change this column to a factor, so that I can use it in functions and graph it, etc. It's useless in this format. I think that once I can remove the levels, I can use as.Date or as.POSIXct to do this, but I need to figure out what's happening in the first part of the question. Here's the R code for just looking at the first value of the timestamp column: antdist$ts[1] [1] 6/1/2013 08:07:39 144873 Levels: 6/1/2013 08:07:39 6/1/2013 08:07:41 6/1/2013 08:07:43 6/1/2013 08:07:45 ... 8/2/2013 11:47:51 Here's a photo of what the first few rows of the timestamp column look like using View(antdist): http://r.789695.n4.nabble.com/file/n4687977/Capture.jpg Thank you, thank you, thank you for your help! -- View this message in context: http://r.789695.n4.nabble.com/MULTIPLE-LEVELS-for-a-SINGLE-VALUE-in-a-dataframe-how-do-I-remove-these-tp4687977.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] Process Forked at MAC
Dear Guys.. Thank you very much for taking time to answer these questions. I 'm running simple command directly on R console: corpus=tm_map(corpus,tolower) giving this result: The process has forked and you cannot use this CoreFoundation functionality safely. You MUST exec(). Once and again. tm and SnowballC installed. Runing: R 3.0.3 GUI 1.63 Snow Leopard build (6660) I tried restarting system, deleting start-up sw, but nothing. Your help will be much appreciated. Thank you. Rodrigo. Hardware info: Nombre del modelo:MacBook Air Identificador del modelo: MacBookAir4,2 Nombre del procesador:Intel Core i5 Velocidad del procesador: 1,7 GHz Cantidad de procesadores: 1 Cantidad total de núcleos:2 Caché de nivel 2 (por núcleo):256 KB Caché de nivel 3: 3 MB Memoria: 4 GB Versión de la ROM de arranque:MBA41.0077.B0F Versión SMC (sistema):1.73f66 Número de serie (sistema):C02GTG2WDJWT UUID de hardware: 96E5DEFD-3601-54ED-BB3B-4AF4DAC2F775 Software: Versión del sistema: Mac OS X 10.7.5 (11G63b) Versión del kernel: Darwin 11.4.2 Volumen de arranque: Macintosh HD Modo de arranque: Normal Memoria virtual segura: Activado Extensiones y kernel de 64 bits: Sí Tiempo desde el arranque: 1:24 __ 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] 127.0.0.1:22381/doc/html/index.html won't start
On 01/04/2014, 4:13 PM, Christian Hoffmann wrote: Dear All, Sorry to bother you. I am using Aquamacs 3.0a (GNU Emacs 24.3.50.2), newly installed. Somehow, on my mac even the newly installed R3.0.3 will mill endlessly after M-x R waiting for 127.0.0.1:22381/doc/html/index.html to load. How can I find out, what is wrong with my configuration? There is an ESS-specific help list; you might have better luck there: https://stat.ethz.ch/mailman/listinfo/ess-help. Duncan Murdoch Thanks for considering. Christian __ 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] Centered difference operation on matrix with R
Dear list members, The answer is in package pracma, function gradient. Regards, Pascal Oettli On Fri, Mar 28, 2014 at 2:51 PM, Pascal Oettli kri...@ymail.com wrote: Dear list members, I am wondering whether there is any more efficient way to calculate centered difference on matrix in R? Please see herewith an example: lon - matrix(rep(seq(0,2,length.out=1e3), 1e3), 1e3, 1e3) lat - matrix(rep(seq(0,2,length.out=1e3), each=1e3), 1e3, 1e3) x - matrix(rep(seq(0.01,2,length.out=1e3), 1e3), 1e3, 1e3) y - matrix(rep(seq(0.01,2,length.out=1e3), each=1e3), 1e3, 1e3) u - y * cos(x) v - y * sin(x) to.rad - pi/180 dx - diff(lon,2); dx - rbind(NA,dx,NA); dx - dx*to.rad dy - t(diff(t(lat),2)); dy - cbind(NA,dy,NA); dy - dy*to.rad du - t(diff(t(u * cos(lat*to.rad)),2)); du - cbind(NA,du,NA) dv - diff(v,2); dv - rbind(NA,dv,NA) Best Regards, Pascal Oettli -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan __ 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] labelling a plot in binom library function call
Hello, The binom package is using ggplot2 to plot the density. Thus, you have to follow the ggplot2 syntax: R binom.bayes.densityplot(hpdc) + ggtitle(my plot) HTH Pascal On Tue, Apr 1, 2014 at 7:41 AM, Chris chris.bar...@barkerstats.com wrote: Hi, I'm using a function in the binom library. I'd like to add a title(s) to the plot generated by binom.bayes.densityplot. I get an error message when trying to use the title function The error message is: Error in title(main = my plot) : plot.new has not been called yet occurs after running the title command. Example code: hpdc - binom.bayes( x = 0:10, n = 10, type = central, conf.level = 0.8, tol = 1e-9) print(hpdc) binom.bayes.densityplot(hpdc) title(main=my plot) I was also unsuccessful in passing a plot title to the function call. And issuing a plot.new() before the title command clears the plot. Thanks in advance for suggestions. Chris Barker, Ph.D. Adjunct Associate Professor of Biostatistics - UIC-SPH and President and Owner Statistical Planning and Analysis Services, Inc. www.barkerstats.com 415 609 7473415 609 7473 skype: barkerstats Call Send SMS Add to Skype You'll need Skype CreditFree via Skype [[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. -- Pascal Oettli Project Scientist JAMSTEC Yokohama, Japan __ 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] Difficulty coding time-forced functions in deSolve
Hi all, I'm trying to use deSolve to solve a series of differential equations with rk4 mimicking a SEIR model, while including an event/function that is not solely time-dependent. Explicitly: I want to introduce vaccination 7 days after the proportion of I2/N2 reaches 0.01. Here is the code I am using: require(deSolve) require(sfsmisc) SEIR - function(t, x, p) { with(as.list(c(x,p)),{ dS-b*N-d*S-beta*S*I/N-V(I, N, t)*S dE- -d*E+beta*S*I/N -epsilon*E-V(I, N, t)*E dI- -d*I+epsilon*E-gamma*I-mu*I-V(I, N, t)*I dR--d*R+gamma*I+V(I, N, t)*S+V(I, N, t)*E+V(I, N, t)*I dN-dS+dE+dI+dR list(c(dS, dE, dI, dR, dN)) }) } V -function(I, N, t) {ifelse(t =8 I[t-7]/N[t-7]0.01, 0.25, 0)} num_years - 10.0 time_limit -num_years*365.00 Ni -1.0E3 b -1/(10.0*365) d -b beta -0.48 epsilon -1/4 gamma -1/4 mu --log(1-0.25)*gamma parms -c(Ni=Ni, b=b, d=d, beta=beta, epsilon=epsilon, gamma=gamma, mu=mu) xstart -c(S=999, E=0, I=1, R=0, N=1000) times - seq(0.0, time_limit, 1.0) tol - 1e-16 my.atol - rep(tol,5) my.rtol - 1e-12 out_rk4 - as.data.frame(rk4(xstart, times, SEIR, parms)) outfilename - paste(Basic SEIR.csv) write.csv(out_rk4,file=outfilename,row.names=FALSE, col.names=FALSE) If I remove function V and the associated parts within the differential equations, the model runs just fine. If I define V as V-function(I, N) {ifelse(I/N 0.01, 0.25, 0) the model functions just fine. Any pointers as to how I can code a function that relies on solutions from previous time steps? thank you in advance, Aimee. __ 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] MULTIPLE LEVELS for a SINGLE VALUE in a dataframe, how do I remove these?
Hi 'What is your name?' When you read the data into R the first column was interpreted as a factor where the levels are the timestamps. If you used read.table() there is the stringsAsFactor you can set to FALSE so that the first column will be read in as strings instead of a factor. However you can now do this. antdist$ts - as.character(antdist$ts) antdist$ts - as.POSIXct(strptime(antdist$ts, format = %m/%d/%Y %H:%M:%S)) See ?factor, ?as.POSIXct, ?strptime Yours sincerely / Med venlig hilsen Frede Aakmann Tøgersen Specialist, M.Sc., Ph.D. Plant Performance Modeling Technology Service Solutions T +45 9730 5135 M +45 2547 6050 fr...@vestas.com http://www.vestas.com Company reg. name: Vestas Wind Systems A/S This e-mail is subject to our e-mail disclaimer statement. Please refer to www.vestas.com/legal/notice If you have received this e-mail in error please contact the sender. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of elle Sent: 1. april 2014 20:35 To: r-help@r-project.org Subject: [R] MULTIPLE LEVELS for a SINGLE VALUE in a dataframe, how do I remove these? I have a series of dates and times in one column. They are all in the format %m/%d/%Y %H:%M:%S; however, they are character values. I have a number of problems: 1) if I use antdist$ts[1] to just examine the FIRST value of the timestamp (ts) column, it shows that there are 144873 Levels, and it should only have 1 Level with the first value of 6/1/2013 08:07:39; how do I delete the remaining levels? 2) I need to change this column to a factor, so that I can use it in functions and graph it, etc. It's useless in this format. I think that once I can remove the levels, I can use as.Date or as.POSIXct to do this, but I need to figure out what's happening in the first part of the question. Here's the R code for just looking at the first value of the timestamp column: antdist$ts[1] [1] 6/1/2013 08:07:39 144873 Levels: 6/1/2013 08:07:39 6/1/2013 08:07:41 6/1/2013 08:07:43 6/1/2013 08:07:45 ... 8/2/2013 11:47:51 Here's a photo of what the first few rows of the timestamp column look like using View(antdist): http://r.789695.n4.nabble.com/file/n4687977/Capture.jpg Thank you, thank you, thank you for your help! -- View this message in context: http://r.789695.n4.nabble.com/MULTIPLE- LEVELS-for-a-SINGLE-VALUE-in-a-dataframe-how-do-I-remove-these- tp4687977.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.