Re: [R] pch size in a legend
Could you provide an example of trying to use pt.cex that "does not do the job"? Using pt.cex works fine for me when I've used it (R version 3.1.2 both 32 bit and 64 bit). Here's some dummy code that demonstrates that the symbol size changes w/o changing the text size: plot(x=c(0,6),y=c(0,6),type="n") legend(x="bottomright",title="Legend 1, symbol 2 with pt.cex=1.25",legend=c("Item 1","Item 2"),pch=c(1,1),pt.cex=c(1,1.25),col=c('black','blue')) legend(x="topleft",title="Legend 2, symbol 2 with pt.cex=1.75",legend=c("Item 1","Item 2"),pch=c(1,1),pt.cex=c(1,1.75),col=c('black','blue')) see if that works for you? __ Allen Bingham Bingham Statistical Consulting aebingh...@gmail.com -Original Message- From: Ahmed Attia [mailto:ahmedati...@gmail.com] Sent: Friday, January 30, 2015 1:50 PM To: r-help Subject: [R] pch size in a legend Hi R users, I would like to adjust the pch size in a legend without changing the text size, pt.cex does not do the job. R 2.15.2 32 bit. legend(0,2100, legend=c("2009","2010","2012","2013","2014"), col = 1,cex=1,lty=NA,pch=c(1,2,6,7,8),lwd=2,bty="n") Thanks Ahmed Attia, Ph.D. Agronomist & Soil Scientist Post-Doc Research Associate Texas A&M AgriLife Research-Vernon ahmed.at...@ag.tamu.edu Cell phone: 001-979-248-5215 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Melt and Rbind/Rbindlist
It would have been nice if you had at least supplied a subset (~10 lines) from a couple of files so we could see what the data looks like and test out any solution. Since you are using 'data.table', you should probably also use 'fread' for reading in the data. Here is a possible approach of reading the data into a list and then creating a single, large data.table: --- myDTs <- lapply(filelist, function(.file) { tmp1 <- fread(.file, sep=",") tmp2 <- melt(tmp1, id="FIPS") tmp2$year <- as.numeric(substr(tmp2$variable,2,5)) tmp2$month <- as.numeric(substr(tmp2$variable,7,8)) tmp2$day <- as.numeric(substr(tmp2$variable,10,11)) tmp2 # return value }) bigDT <- rbindlist(myDTs) # rbind all the data.tables together # then you should be able to do: mean.temp <- bigDT[, list(temp.mean=lapply(.SD, mean), by=c("FIPS","year","month"), .SDcols=c("temp")] Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Sat, Jan 31, 2015 at 5:57 PM, Shouro Dasgupta wrote: > I have climate data for 20 years for US counties (FIPS) in csv format, each > file represents one year of data. I have extracted the data and reshaped > the yearly data files using melt(); > > for (i in filelist) { > > tmp1 <- as.data.table(read.csv(i,header=T, sep=",")) > > tmp2 <- melt(tmp1, id="FIPS") > > tmp2$year <- as.numeric(substr(tmp2$variable,2,5)) > > tmp2$month <- as.numeric(substr(tmp2$variable,7,8)) > > tmp2$day <- as.numeric(substr(tmp2$variable,10,11)) > > } > > > Should I *rbind *in the loop here as I have the memory? > So, the file (i) tmp2 looks like this: > > FIPS temp year month date > > 1001 276.7936 2045 1 1/1/2045 > > 1003 276.7936 2045 1 1/1/2045 > > 1005 279.6452 2045 1 1/1/2045 > > 1007 276.7936 2045 1 1/1/2045 > > 1009 272.3748 2045 1 1/1/2045 > > 1011 279.6452 2045 1 1/1/2045 > > > My goal is calculate the mean by FIPS code by month/week, however, when I > use the following code, I get a NULL value. > > mean.temp<- for (i in filelist) {tmp2[, list(temp.mean=lapply(.SD, mean), > > by=c("FIPS","year","month"), .SDcols=c("temp")]} > > > This works fine for individual years but with *for (i in filelist)*. What > am I doing wrong? Can include a rbind/bindlist in the loop to make a big > data.frame? Any suggestions will be highly appreciated. Thank you. > > Sincerely, > > Shouro > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dropping time series observations
On Sat, Jan 31, 2015 at 2:16 PM, Mikael Olai Milhøj wrote: > Hi > > Is there an easy way to drop, for instance, the first 4 observation of a > time series object in R? I have tried to google the answer without any > luck. > > To be more clear: > Let us say that I have a time seres object x which data from 2000Q1 to > 2014Q4 but I only want the data from 2001Q1 to 2014Q4.How do I remove the > first four elements? > > By using x[5:?] R no longer recognize it as a ts.object. > 1. We could convert it to a zoo series, drop the first 4 and convert back: For example, using the built in presidents ts series: library(zoo) as.ts(tail(as.zoo(presidents), -4)) 1a. This would work too: library(zoo) as.ts(as.zoo(presidents)[-(1:4)]) 2. Using only base R one can use window like this since 4 observations is one cycle (given that the frequency of the presidents dataset is 4. window(presidents, start = start(presidents) + 1) or in terms of 4: window(presidents, start = start(presidents) + 4 * deltat(presidents)) Here deltat is the time between observations so we want to start 4 deltat's later. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Melt and Rbind/Rbindlist
I have climate data for 20 years for US counties (FIPS) in csv format, each file represents one year of data. I have extracted the data and reshaped the yearly data files using melt(); for (i in filelist) { > tmp1 <- as.data.table(read.csv(i,header=T, sep=",")) > tmp2 <- melt(tmp1, id="FIPS") > tmp2$year <- as.numeric(substr(tmp2$variable,2,5)) > tmp2$month <- as.numeric(substr(tmp2$variable,7,8)) > tmp2$day <- as.numeric(substr(tmp2$variable,10,11)) > } Should I *rbind *in the loop here as I have the memory? So, the file (i) tmp2 looks like this: FIPS temp year month date > 1001 276.7936 2045 1 1/1/2045 > 1003 276.7936 2045 1 1/1/2045 > 1005 279.6452 2045 1 1/1/2045 > 1007 276.7936 2045 1 1/1/2045 > 1009 272.3748 2045 1 1/1/2045 > 1011 279.6452 2045 1 1/1/2045 My goal is calculate the mean by FIPS code by month/week, however, when I use the following code, I get a NULL value. mean.temp<- for (i in filelist) {tmp2[, list(temp.mean=lapply(.SD, mean), > by=c("FIPS","year","month"), .SDcols=c("temp")]} This works fine for individual years but with *for (i in filelist)*. What am I doing wrong? Can include a rbind/bindlist in the loop to make a big data.frame? Any suggestions will be highly appreciated. Thank you. Sincerely, Shouro [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dropping time series observations
For class 'ts' the 'window' function in the base package will do it. > x <- ts(101:117, start=2001.75, frequency=4) > x Qtr1 Qtr2 Qtr3 Qtr4 2001 101 2002 102 103 104 105 2003 106 107 108 109 2004 110 111 112 113 2005 114 115 116 117 > window(x, start=2002.5) Qtr1 Qtr2 Qtr3 Qtr4 2002104 105 2003 106 107 108 109 2004 110 111 112 113 2005 114 115 116 117 > window(x, end=2002.5) Qtr1 Qtr2 Qtr3 Qtr4 2001 101 2002 102 103 104 Bill Dunlap TIBCO Software wdunlap tibco.com On Sat, Jan 31, 2015 at 11:16 AM, Mikael Olai Milhøj wrote: > Hi > > Is there an easy way to drop, for instance, the first 4 observation of a > time series object in R? I have tried to google the answer without any > luck. > > To be more clear: > Let us say that I have a time seres object x which data from 2000Q1 to > 2014Q4 but I only want the data from 2001Q1 to 2014Q4.How do I remove the > first four elements? > > By using x[5:?] R no longer recognize it as a ts.object. > > Thank you > > Best regards > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] The R Journal, Volume 6, Issue 2
Dear All, The latest issue of The R Journal is now available at http://journal.r-project.org/archive/2014-2/ Many thanks to all contributors. Regards, -Deepayan ___ r-annou...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-announce __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Dropping time series observations
Hi Is there an easy way to drop, for instance, the first 4 observation of a time series object in R? I have tried to google the answer without any luck. To be more clear: Let us say that I have a time seres object x which data from 2000Q1 to 2014Q4 but I only want the data from 2001Q1 to 2014Q4.How do I remove the first four elements? By using x[5:?] R no longer recognize it as a ts.object. Thank you Best regards [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Failure to execute R CMD SHLIB successfully
R 3.1.2 Windows 7 Colleagues I am working with c code that reads sas7bdat files into R. I have been successful in compiling and running the code in both OS X and Windows. Recently, the author of the c code added code that calls iconv.h (in order to convert encodings). Using the new version of the c code, I can run compile and run the code in OS X without problems. However, when I run the code in Windows, I encounter a series of warnings, followed by what appear to be errors — and the code is not compiled. I have installed the latest version of Rtools and I have set the path as follows: set PATH=c:\Rtools\bin;c:\Rtools\gcc-4.6.3\bin;c:\program files (c86)\gnuwin32\bin;c:\MiKTeX\miktex\bin;%R32%;c:\windows;c:\windows\system32 where R32 is the path to the 32-but version of R The command that I execute is: R CMD SHLIB -o ../compiled/Windows32.so ConvertSAS.c CKHashTable.c readstat_convert.c readstat_bits.c readstat_io.c readstat_sas.c) I get a series of warnings: > gcc -m32 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG > -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 > -mtune=core2 -c ConvertSAS.c -o ConvertSAS.o > gcc -m32 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG > -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 > -mtune=core2 -c CKHashTable.c -o CKHashTable.o > gcc -m32 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG > -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 > -mtune=core2 -c readstat_convert.c -o readstat_convert.o > readstat_convert.c: In function 'readstat_convert': > readstat_convert.c:23:9: warning: passing argument 2 of 'libiconv' from > incompatible pointer type [enabled by default] > iconv.h:92:37: note: expected 'const char **' but argument is of type 'char > **' > gcc -m32 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG > -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 > -mtune=core2 -c readstat_bits.c -o readstat_bits.o > readstat_bits.c: In function 'byteswap_float': > readstat_bits.c:59:5: warning: dereferencing type-punned pointer will break > strict-aliasing rules [-Wstrict-aliasing] > readstat_bits.c:60:5: warning: dereferencing type-punned pointer will break > strict-aliasing rules [-Wstrict-aliasing] > readstat_bits.c: In function 'byteswap_double': > readstat_bits.c:64:5: warning: dereferencing type-punned pointer will break > strict-aliasing rules [-Wstrict-aliasing] > readstat_bits.c:65:5: warning: dereferencing type-punned pointer will break > strict-aliasing rules [-Wstrict-aliasing] > gcc -m32 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG > -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 > -mtune=core2 -c readstat_io.c -o readstat_io.o > gcc -m32 -I"C:/PROGRA~1/R/R-31~1.2/include" -DNDEBUG > -I"d:/RCompile/CRANpkg/extralibs64/local/include" -O3 -Wall -std=gnu99 > -mtune=core2 -c readstat_sas.c -o readstat_sas.o > readstat_sas.c: In function 'sas_read_header': > readstat_sas.c:204:20: warning: variable 'a2' set but not used > [-Wunused-but-set-variable] > readstat_sas.c: In function 'sas_parse_page_pass1': > readstat_sas.c:788:23: warning: variable 'subheader_type' set but not used > [-Wunused-but-set-variable] > readstat_sas.c:770:14: warning: variable 'page_type' set but not used > [-Wunused-but-set-variable] > readstat_sas.c: In function 'sas_parse_page_pass2': > readstat_sas.c:861:27: warning: variable 'subheader_type' set but not used > [-Wunused-but-set-variable] > readstat_sas.c: In function 'parse_sas7bdat': > readstat_sas.c:1029:9: warning: implicit declaration of function 'dprintf' > [-Wimplicit-function-declaration] > followed by a series of errors: > gcc -m32 -shared -s -static-libgcc -o ../compiled/Windows32.so tmp.def > ConvertSAS.o CKHashTable.o readstat_convert.o readstat_bits.o readstat_io.o > readstat_sas.o -Ld:/RCompile/CRANpkg/extralibs64/local/lib/i386 > -Ld:/RCompile/CRANpkg/extralibs64/local/lib -LC:/PROGRA~1/R/R-31~1.2/bin/i386 > -lR > readstat_convert.o:readstat_convert.c:(.text+0x42): undefined reference to > `_imp__libiconv' > readstat_sas.o:readstat_sas.c:(.text+0x10b5): undefined reference to > `_imp__libiconv_close' > readstat_sas.o:readstat_sas.c:(.text+0x1126): undefined reference to > `_imp__libiconv_open' > readstat_sas.o:readstat_sas.c:(.text+0x1808): undefined reference to `dprintf' > readstat_sas.o:readstat_sas.c:(.text+0x1da1): undefined reference to > `_imp__libiconv_open' > readstat_sas.o:readstat_sas.c:(.text+0x1de4): undefined reference to > `_imp__libiconv_close' > collect2: ld returned 1 exit status > The errors all reference libiconv. Note that the first line in the errors references extralibs64. I don’t understand where this is coming from since the gcc command is created by R CMD SHLIB using the 32-fit version of R. I replaced both instance of extralibs64 with extralibs32 but the identical error m
Re: [R] naming rows/columns in 'array of matrices' | solved
You can also add names to the dimensions: > dimnames(P)[[1]] <- c("live","dead") > dimnames(P)[[2]] <- c("old","young") > names(dimnames(P)) <- c("status", "age", NULL) > P , , 1 age status old young live 1 2 dead 3 4 , , 2 age status old young live 5 6 dead 7 8 David L. Carlson Department of Anthropology Texas A&M University -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of peter dalgaard Sent: Saturday, January 31, 2015 2:19 AM To: Evan Cooch Cc: r-help@r-project.org Subject: Re: [R] naming rows/columns in 'array of matrices' | solved > On 30 Jan 2015, at 20:34 , Evan Cooch wrote: > > The (obvious, after the fact) solution at the bottom. D'oh... > [snip] > Forgot I was dealing with a multi-dimensional array, not a list. So, > following works fine. I'm sure there are better approaches (where 'better' is > either 'cooler', or 'more flexible'), but for the moment...) > > P <- array(0, c(2,2,2),dimnames=list(c("live","dead"),c("old","young"),NULL)) > > P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T); > P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T); > > print(P); > Just for completeness, this also works: > P <- array(0, c(2,2,2)) > P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T); > P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T); > dimnames(P)[[1]] <- c("live","dead") > dimnames(P)[[2]] <- c("live","dead") -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Updating CRAN Website
Greetings I wanted to suggest that the CRAN website needs to be updated to look and fuction more like the Python website (https://www.python.org/). Hopefully better. I know this is an open source project and I am more appreciative of this project than you know. But, I would like to see it advance. Python is open source as well and the website is a lot more user friendly and aesthetically pleasing that the CRAN website. Thank you for your time and consideration. Alton [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How can I get the same result after running function maximinESE_LHS?
Because your code includes set.seed, I would expect that running it all from scratch should lead to the same result every time. I an not familiar with that specific package, so there could be a surprise in it, but unlikely. I suspect that you are running parts of the code to get different results. Please read the Posting Guide, which among other things mentions that this is a plain text email list. Failing to send your email in plain text leads to us not seeing what you sent as you saw it, which leads to problems understanding each other. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. 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 January 31, 2015 4:12:55 AM PST, VIP <850939...@qq.com> wrote: >Hi All, >Recently I'm doing my thesis with LHS, and I created the design by >using the folloing code. >"require(DiceDesign) >require(DoE.wrapper) >set.seed(27662) >LHD=lhs.design(200,7,type="dmax",factor.names=list( > Angle1=c(80,90),Angle2=c(90,100), > Angle3=c(32,40),Radial2=c(10,15), > Radial3=c(25,35),Length1=c(120,130), > Length2=c(0,10)),range=0.98,niter_max=2000) >LHDnew=maximinESE_LHS(LHD,T0=0.005*phiP(LHD,p=50),inner_it=200,J=50,it=4) >plot(LHDnew$design$Angle1,LHDnew$design$Angle2) >plot(LHDnew$critValues,type="l") >LHDopt=LHDnew$design" >As R language is new for me, Each time I run the code, the different >LHDopt can get. I don't know how can I avoid this situation. >Anybody could help me? >BR, >Dean > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] quetion about matrix compute
Here is another implementation: > b [1] 1 2 3 4 5 > c [1] 1 2 1 3 5 4 > outer(c,b, "==")*1 [,1] [,2] [,3] [,4] [,5] [1,]10000 [2,]01000 [3,]10000 [4,]00100 [5,]00001 [6,]00010 I hope this helps. Chel Hee Lee On 1/30/2015 11:52 AM, JS Huang wrote: Hi, Here is my implementation. Hope this helps. b [1] 1 2 3 4 5 c [1] 1 2 1 3 5 4 sapply(b,function(x)ifelse(x==c,1,0)) [,1] [,2] [,3] [,4] [,5] [1,]10000 [2,]01000 [3,]10000 [4,]00100 [5,]00001 [6,]00010 -- View this message in context: http://r.789695.n4.nabble.com/quetion-about-matrix-compute-tp4702505p4702532.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error in submission
This is clearly a homework problem and probably one for an online Coursera course. If that guess is correct, then you should be using the facilities for help through the course website. On Jan 31, 2015, at 2:11 AM, Wael Hammam Fouad wrote: > R x64 3.1.2 RStudio win8.1 64x error in submission > assignment 3 best function > *actually i have 2 code * > *the first have good **output but error in submission :* > *Selection: 1Error in best("BB", "heart attack") : Invalid stateCalled > from: .rs.breakOnError(TRUE)* > best <- function(state, outcome) { >outmeasures <- read.csv("outcome-of-care-measures.csv", colClasses > = "character") >caremeasures <- subset(outmeasures,,select=c("Hospital.Name", > "State" > , > "Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack" > , > "Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure" > , > "Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia")) >names(caremeasures) <- c("Hospital.Name", "State", "Heart.Attack", > "Heart.Failure", "Pneumonia") >measuresstate <- subset(caremeasures[caremeasures$State == state , > c("Hospital.Name", "State" , > "Heart.Attack", "Heart.Failure", > "Pneumonia")]) >if(!state %in% measuresstate$State) { >stop("Invalid state") >} >if(outcome == "heart attack") { >minHos <- measuresstate[, c("Hospital.Name", > "Heart.Attack")] >minHos[, "Heart.Attack"] <- > suppressWarnings(as.numeric(minHos[, "Heart.Attack"])) >minHosN <- na.omit(minHos) >minHospital <- minHosN[with(minHosN, order(Heart.Attack, > Hospital.Name)), ] >return(minHospital[[1]][[1]]) >}else if(outcome == "heart failure") { >minHos <- measuresstate[, c("Hospital.Name", > "Heart.Failure")] >minHos[, "Heart.Failure"] <- > suppressWarnings(as.numeric(minHos[, "Heart.Failure"])) >minHosN <- na.omit(minHos) >minHospital <- minHosN[with(minHosN, order(Heart.Failure, > Hospital.Name)), ] >return(minHospital[[1]][[1]]) >}else if(outcome == "pneumonia") { >minHos <- measuresstate[, c("Hospital.Name", "Pneumonia")] >minHos[, "Pneumonia"] <- > suppressWarnings(as.numeric(minHos[, "Pneumonia"])) >minHosN <- na.omit(minHos) >minHospital <- minHosN[with(minHosN, order(Pneumonia, > Hospital.Name)), ] >return(minHospital[[1]][[1]]) >}else{ >stop("Invalid outcome") >} > } > > > *the second have error* (best("BB", "heart attack") > Error in minHospital[[1]][[1]] : subscript out of bounds) > > *and it's looks like no check on state the is as follow :* That phrase cannot be parsed by this native-speaker. > best <- function(state, outcome) { >outmeasures <- read.csv("outcome-of-care-measures.csv", > stringsAsFactors=FALSE, na.strings="Not Available") >if(!state %in% outmeasures$State | > !outcome %in% > outmeasures$Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack | > !outcome %in% > outmeasures$Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure | > !outcome %in% > outmeasures$Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia) { >caremeasures <- subset(outmeasures,,select=c("Hospital.Name", > "State" >, > "Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack" >, > "Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure" >, > "Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia")) >names(caremeasures) <- c("Hospital.Name", "State", "Heart.Attack", > "Heart.Failure", "Pneumonia") >measuresstate <- subset(caremeasures[caremeasures$State == state , >c("Hospital.Name", "State" , > "Heart.Attack", > "Heart.Failure", "Pneumonia")]) >if(outcome == "heart attack") { >minHos <- measuresstate[, c("Hospital.Name", > "Heart.Attack")] >minHos[, "Heart.Attack"] <- > suppressWarnings(as.numeric(minHos[, "Heart.Attack"])) >minHosN <- na.omit(minHos) >minHospital <- minHosN[with(minHosN, order(Heart.Attack, > Hospital.Name)), ] >return(minHospital[[1]][[1]]) >}else if(outcome == "heart failure") { >minHos <- measuresstate[, c("Hospital.Name", > "Heart.Failure")] >minHos[, "Heart.Failure"] <- > suppressWarnings(as.numeric(minHos[, "Heart
Re: [R] pch size in a legend
Hi Ahmed, It also works with the following working environment: > R.version _ platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 status major 3 minor 1.2 year 2014 month 10 day31 svn rev66913 language R version.string R version 3.1.2 (2014-10-31) nickname Pumpkin Helmet > unlist(.Platform) OS.type file.sep dynlib.ext GUI endian pkgType "windows" "/" ".dll" "Rgui" "little" "win.binary" path.sep r_arch ";""x64" > Chel Hee Lee On 1/30/2015 9:55 PM, Jim Lemon wrote: Hi Ahmed, Hmmm, this seems to work for me (R-3.1.2, Linux) legend(0,2100, legend=c("2009","2010","2012","2013","2014"), col = 1,cex=1,lty=NA,pch=c(1,2,6,7,8),lwd=2,bty="n",pt.cex=2) Jim On Sat, Jan 31, 2015 at 8:49 AM, Ahmed Attia wrote: Hi R users, I would like to adjust the pch size in a legend without changing the text size, pt.cex does not do the job. R 2.15.2 32 bit. legend(0,2100, legend=c("2009","2010","2012","2013","2014"), col = 1,cex=1,lty=NA,pch=c(1,2,6,7,8),lwd=2,bty="n") Thanks Ahmed Attia, Ph.D. Agronomist & Soil Scientist Post-Doc Research Associate Texas A&M AgriLife Research-Vernon ahmed.at...@ag.tamu.edu Cell phone: 001-979-248-5215 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R problem
> ex <- strptime(c("2014-01-30 15:39:46", "2012-04-20 14:49:02"), format="%Y-%m-%d %H:%M:%S") > ex [1] "2014-01-30 15:39:46 CST" "2012-04-20 14:49:02 CST" > format(ex, format="%a") [1] "Thu" "Fri" > format(ex, format="%A") [1] "Thursday" "Friday" > weekdays(ex) [1] "Thursday" "Friday" > Is this what you are looking for? I hope this helps. Chel Hee Lee On 1/31/2015 3:06 AM, Camilla Timo wrote: Hi there, I have a problem, i have a dataset, in which there are time series from 2010- to 2014, like this: -2014-01-30 15:39:46 -2012-04-20 14:49:02 And so on . I want to have a situation in which there are days of week expressed in word, because I have to calculate days of week and on the other hand week end. For example, i want : -2014- 01 monday 15:39:46 -2012-04 saturday 14:49:02 Thanks guys Inviato da iPhone __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R problem
This post should help http://stackoverflow.com/questions/9216138/find-the-day-of-a-week-in-r John Kane Kingston ON Canada > -Original Message- > From: cami090...@icloud.com > Sent: Sat, 31 Jan 2015 10:06:08 +0100 > To: r-help@r-project.org > Subject: [R] R problem > > Hi there, > I have a problem, i have a dataset, in which there are time series from > 2010- to 2014, like this: > -2014-01-30 15:39:46 > -2012-04-20 14:49:02 > And so on . > I want to have a situation in which there are days of week expressed in > word, because I have to calculate days of week and on the other hand week > end. For example, i want : > -2014- 01 monday 15:39:46 > -2012-04 saturday 14:49:02 > Thanks guys > > Inviato da iPhone > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. Can't remember your password? Do you need a strong and secure password? Use Password manager! It stores your passwords & protects your account. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use curve() function without using x as the variable name inside expression?
Hi Philippe, Ah! Thanks for pointing out the pesky ifelse() issue. I have only recently been learning (the hard way) that ifelse() is not a tool for the uninformed like me, but it is ever so tempting! I would like to offer another way to speed things up. findInterval() can be quite fast, and the speed up is most noticeable when the size of the input grows (note I made input x <- 1:3000). func <- function (x, mn, mx) 1/(mx-mn) * (x >= mn & x <= mx) funcIfElse <- function (x, mn, mx) ifelse(x < mn | x > mx, 0, 1/(mx - mn)) funcFindInterval <- function(x, mn, mx) 1/(mx - mn) * (findInterval(x, c(mn, mx), rightmost.closed = TRUE) == 1) mn<- 100; mx <- 200; x <- 1:3000 microbenchmark::microbenchmark(func(x, mn, mx), funcIfElse(x, mn, mx), funcFindInterval(x, mn, mx)) #Unit: microseconds #expr min lq mean median uq max neval # func(x, mn, mx) 74.920 76.006 88.57119 76.5635 78.7065 897.333 100 # funcIfElse(x, mn, mx) 728.388 733.206 832.02225 735.4280 796.1910 1645.804 100 # funcFindInterval(x, mn, mx) 33.954 35.334 56.57323 36.5010 38.3340 993.193 100 r1 <- func(x, mn, mx) r2 <- funcIfElse(x, mn, mx) r3 <- funcFindInterval(x, mn, mx) identical(r1, r2) #[1] TRUE identical(r2, r3) #[1] TRUE Cheers, Ben On Jan 31, 2015, at 4:03 AM, Philippe Grosjean wrote: > Also note that ifelse() should be avoided as much as possible. To define a > piecewise function you can use this trick: > > func <- function (x, min, max) 1/(max-min) * (x >= min & x <= max) > > The performances are much better. This has no impact here, but it is a good > habit to take in case you manipulate such kind of functions in a more > computing-intensive context (numerical integration, nls(), etc.). > > funcIfElse <- function (x, min, max) ifelse(x < min | x > max, 0, 1/(max - > min)) > min <- 100; max <- 200; x <- 1:300 > microbenchmark::microbenchmark(func(x, min, max), funcIfElse(x, min, max)) > ## Unit: microseconds > ## exprmin lq mean median > uq max neval > ## func(x, min, max) 10.242 16.0175 18.43348 18.446 19.8680 > 47.266 100 > ## funcIfElse(x, min, max) 90.386 125.1605 148.18555 143.455 148.6695 > 1203.292 100 > > Best, > > Philippe Grosjean > >> On 31 Jan 2015, at 09:39, Rolf Turner wrote: >> >> On 31/01/15 21:10, C W wrote: >>> Hi Bill, >>> >>> One quick question. What if I wanted to use curve() for a uniform >>> distribution? >>> >>> Say, unif(0.5, 1.3), 0 elsewhere. >>> >>> My R code: >>> func <- function(min, max){ >>> 1 / (max - min) >>> } >>> >>> curve(func(min = 0.5, max = 1.3), from = 0, to = 2) >>> >>> curve() wants an expression, but I have a constant. And I want zero >>> everywhere else. >> >> Well if that's what you want, then say so!!! >> >> func <- function(x,min,max) { >> ifelse(x < min | x > max, 0, 1/(max - min)) >> } >> >> curve(func(u,0.5,1.3),0,2,xname="u") >> >> Or, better (?) curve(func(u,0.5,1.3),0,2,xname="u",type="s") >> >> which avoids the slight slope in the "vertical" lines. >> >> cheers, >> >> Rolf Turner >> >> -- >> Rolf Turner >> Technical Editor ANZJS >> Department of Statistics >> University of Auckland >> Phone: +64-9-373-7599 ext. 88276 >> Home phone: +64-9-480-4619 >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error in submission
R x64 3.1.2 RStudio win8.1 64x error in submission assignment 3 best function *actually i have 2 code * *the first have good **output but error in submission :* *Selection: 1Error in best("BB", "heart attack") : Invalid stateCalled from: .rs.breakOnError(TRUE)* best <- function(state, outcome) { outmeasures <- read.csv("outcome-of-care-measures.csv", colClasses = "character") caremeasures <- subset(outmeasures,,select=c("Hospital.Name", "State" , "Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack" , "Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure" , "Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia")) names(caremeasures) <- c("Hospital.Name", "State", "Heart.Attack", "Heart.Failure", "Pneumonia") measuresstate <- subset(caremeasures[caremeasures$State == state , c("Hospital.Name", "State" , "Heart.Attack", "Heart.Failure", "Pneumonia")]) if(!state %in% measuresstate$State) { stop("Invalid state") } if(outcome == "heart attack") { minHos <- measuresstate[, c("Hospital.Name", "Heart.Attack")] minHos[, "Heart.Attack"] <- suppressWarnings(as.numeric(minHos[, "Heart.Attack"])) minHosN <- na.omit(minHos) minHospital <- minHosN[with(minHosN, order(Heart.Attack, Hospital.Name)), ] return(minHospital[[1]][[1]]) }else if(outcome == "heart failure") { minHos <- measuresstate[, c("Hospital.Name", "Heart.Failure")] minHos[, "Heart.Failure"] <- suppressWarnings(as.numeric(minHos[, "Heart.Failure"])) minHosN <- na.omit(minHos) minHospital <- minHosN[with(minHosN, order(Heart.Failure, Hospital.Name)), ] return(minHospital[[1]][[1]]) }else if(outcome == "pneumonia") { minHos <- measuresstate[, c("Hospital.Name", "Pneumonia")] minHos[, "Pneumonia"] <- suppressWarnings(as.numeric(minHos[, "Pneumonia"])) minHosN <- na.omit(minHos) minHospital <- minHosN[with(minHosN, order(Pneumonia, Hospital.Name)), ] return(minHospital[[1]][[1]]) }else{ stop("Invalid outcome") } } *the second have error* (best("BB", "heart attack") Error in minHospital[[1]][[1]] : subscript out of bounds) *and it's looks like no check on state the is as follow :* best <- function(state, outcome) { outmeasures <- read.csv("outcome-of-care-measures.csv", stringsAsFactors=FALSE, na.strings="Not Available") if(!state %in% outmeasures$State | !outcome %in% outmeasures$Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack | !outcome %in% outmeasures$Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure | !outcome %in% outmeasures$Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia) { caremeasures <- subset(outmeasures,,select=c("Hospital.Name", "State" , "Hospital.30.Day.Death..Mortality..Rates.from.Heart.Attack" , "Hospital.30.Day.Death..Mortality..Rates.from.Heart.Failure" , "Hospital.30.Day.Death..Mortality..Rates.from.Pneumonia")) names(caremeasures) <- c("Hospital.Name", "State", "Heart.Attack", "Heart.Failure", "Pneumonia") measuresstate <- subset(caremeasures[caremeasures$State == state , c("Hospital.Name", "State" , "Heart.Attack", "Heart.Failure", "Pneumonia")]) if(outcome == "heart attack") { minHos <- measuresstate[, c("Hospital.Name", "Heart.Attack")] minHos[, "Heart.Attack"] <- suppressWarnings(as.numeric(minHos[, "Heart.Attack"])) minHosN <- na.omit(minHos) minHospital <- minHosN[with(minHosN, order(Heart.Attack, Hospital.Name)), ] return(minHospital[[1]][[1]]) }else if(outcome == "heart failure") { minHos <- measuresstate[, c("Hospital.Name", "Heart.Failure")] minHos[, "Heart.Failure"] <- suppressWarnings(as.numeric(minHos[, "Heart.Failure"])) minHosN <- na.omit(minHos) minHospital <- minHosN[with(minHosN, order(Heart.Failure, Hospital.Name)), ] return(minHospital[[1]][[1]]) }else if(outcome == "pneumonia") { minHos <- measuresstate[, c("Hospital.Name", "Pneumonia")] minHos[, "Pneumonia"] <- suppressWarnings(as.numeric(minHos[, "Pneumonia"])) minHosN <- na.omit(
[R] R problem
Hi there, I have a problem, i have a dataset, in which there are time series from 2010- to 2014, like this: -2014-01-30 15:39:46 -2012-04-20 14:49:02 And so on . I want to have a situation in which there are days of week expressed in word, because I have to calculate days of week and on the other hand week end. For example, i want : -2014- 01 monday 15:39:46 -2012-04 saturday 14:49:02 Thanks guys Inviato da iPhone __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How can I get the same result after running function maximinESE_LHS?
Hi All, Recently I'm doing my thesis with LHS, and I created the design by using the folloing code. "require(DiceDesign) require(DoE.wrapper) set.seed(27662) LHD=lhs.design(200,7,type="dmax",factor.names=list( Angle1=c(80,90),Angle2=c(90,100), Angle3=c(32,40),Radial2=c(10,15), Radial3=c(25,35),Length1=c(120,130), Length2=c(0,10)),range=0.98,niter_max=2000) LHDnew=maximinESE_LHS(LHD,T0=0.005*phiP(LHD,p=50),inner_it=200,J=50,it=4) plot(LHDnew$design$Angle1,LHDnew$design$Angle2) plot(LHDnew$critValues,type="l") LHDopt=LHDnew$design" As R language is new for me, Each time I run the code, the different LHDopt can get. I don't know how can I avoid this situation. Anybody could help me? BR, Dean [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] aov and Error function
I am trying to understand the Error function and its use in ANOVA. In particular I want to understand the difference between two models that differ only with respect to the Error statement: aovsubj<- aov(value~group+time+Error(subject),data=dataRMANOVA) and aovsubjgroup<-aov(value~group+time+Error(subject/group),data=dataRMANOVA) You will note that in my data I have two subject identifiers, subject and subject2. I am also trying to trying to understand how I should identify subjects, within group (i.e. intervention vs. control) or within time (0=baseline, 1=post) > dataRMANOVA value time group subject subject2 1 1.000 int 11 2 2.000 int 22 3 3.000 int 33 4 4.000 int 44 5 5.000 int 55 6 6.000 int 66 7 7.000 int 77 8 8.000 int 88 9 9.000 int 99 10 10.000 int 10 10 11 11.000 int 11 11 12 12.000 int 12 12 13 13.000 int 13 13 14 14.000 int 14 14 15 15.000 int 15 15 16 16.000 int 16 16 17 17.000 int 17 17 18 18.000 int 18 18 19 19.000 int 19 19 20 20.000 int 20 20 21 21.000 cont 1 21 22 22.000 cont 2 22 23 23.000 cont 3 23 24 24.000 cont 4 24 25 25.000 cont 5 25 26 26.000 cont 6 26 27 27.000 cont 7 27 28 28.000 cont 8 28 29 29.000 cont 9 29 30 30.000 cont 10 30 31 31.000 cont 11 31 32 32.000 cont 12 32 33 33.000 cont 13 33 34 34.000 cont 14 34 35 35.000 cont 15 35 36 36.000 cont 16 36 37 37.000 cont 17 37 38 38.000 cont 18 38 39 39.000 cont 19 39 40 40.000 cont 20 40 41 2.8791311 int 11 42 1.5336511 int 22 43 2.4877561 int 33 44 3.4460681 int 44 45 5.1798541 int 55 46 5.7758191 int 66 47 6.9239791 int 77 48 8.1637341 int 88 49 9.5459741 int 99 50 8.7921861 int 10 10 51 11.6575031 int 11 11 52 12.6813931 int 12 12 53 15.0586881 int 13 13 54 13.7576731 int 14 14 55 15.4590291 int 15 15 56 15.5355491 int 16 16 57 16.4332371 int 17 17 58 17.2473301 int 18 18 59 19.0619271 int 19 19 60 21.1650031 int 20 20 61 20.4367051 cont 1 21 62 23.1432301 cont 2 22 63 23.4569461 cont 3 23 64 23.1322841 cont 4 24 65 24.9020171 cont 5 25 66 26.4503991 cont 6 26 67 27.3569431 cont 7 27 68 27.4020231 cont 8 28 69 29.7598831 cont 9 29 70 27.9696281 cont 10 30 71 30.0614751 cont 11 31 72 32.5324271 cont 12 32 73 33.3788771 cont 13 33 74 34.8522441 cont 14 34 75 34.9585941 cont 15 35 76 35.6732251 cont 16 36 77 37.9082081 cont 17 37 78 37.9824711 cont 18 38 79 39.0169171 cont 19 39 80 39.5075831 cont 20 40 Thank you, John John David Sorkin M.D., Ph.D. Professor of Medicine Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology and Geriatric Medicine Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use curve() function without using x as the variable name inside expression?
Also note that ifelse() should be avoided as much as possible. To define a piecewise function you can use this trick: func <- function (x, min, max) 1/(max-min) * (x >= min & x <= max) The performances are much better. This has no impact here, but it is a good habit to take in case you manipulate such kind of functions in a more computing-intensive context (numerical integration, nls(), etc.). funcIfElse <- function (x, min, max) ifelse(x < min | x > max, 0, 1/(max - min)) min <- 100; max <- 200; x <- 1:300 microbenchmark::microbenchmark(func(x, min, max), funcIfElse(x, min, max)) ## Unit: microseconds ## exprmin lq mean median uq max neval ## func(x, min, max) 10.242 16.0175 18.43348 18.446 19.8680 47.266 100 ## funcIfElse(x, min, max) 90.386 125.1605 148.18555 143.455 148.6695 1203.292 100 Best, Philippe Grosjean > On 31 Jan 2015, at 09:39, Rolf Turner wrote: > > On 31/01/15 21:10, C W wrote: >> Hi Bill, >> >> One quick question. What if I wanted to use curve() for a uniform >> distribution? >> >> Say, unif(0.5, 1.3), 0 elsewhere. >> >> My R code: >> func <- function(min, max){ >> 1 / (max - min) >> } >> >> curve(func(min = 0.5, max = 1.3), from = 0, to = 2) >> >> curve() wants an expression, but I have a constant. And I want zero >> everywhere else. > > Well if that's what you want, then say so!!! > > func <- function(x,min,max) { > ifelse(x < min | x > max, 0, 1/(max - min)) > } > > curve(func(u,0.5,1.3),0,2,xname="u") > > Or, better (?) curve(func(u,0.5,1.3),0,2,xname="u",type="s") > > which avoids the slight slope in the "vertical" lines. > > cheers, > > Rolf Turner > > -- > Rolf Turner > Technical Editor ANZJS > Department of Statistics > University of Auckland > Phone: +64-9-373-7599 ext. 88276 > Home phone: +64-9-480-4619 > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use curve() function without using x as the variable name inside expression?
> On 31 Jan 2015, at 09:39 , Rolf Turner wrote: > > On 31/01/15 21:10, C W wrote: >> Hi Bill, >> >> One quick question. What if I wanted to use curve() for a uniform >> distribution? >> >> Say, unif(0.5, 1.3), 0 elsewhere. >> >> My R code: >> func <- function(min, max){ >> 1 / (max - min) >> } >> >> curve(func(min = 0.5, max = 1.3), from = 0, to = 2) >> >> curve() wants an expression, but I have a constant. And I want zero >> everywhere else. > > Well if that's what you want, then say so!!! > > func <- function(x,min,max) { > ifelse(x < min | x > max, 0, 1/(max - min)) > } > Oy! help(Uniform) called. I wants its density function back... > curve(func(u,0.5,1.3),0,2,xname="u") > > Or, better (?) curve(func(u,0.5,1.3),0,2,xname="u",type="s") > > which avoids the slight slope in the "vertical" lines. It might put the verticals in the wrong place though. I usually just increase the "n" parameter: curve(dunif(u,.5, 1.3), from=0, to=2, n=5001, xname="u") -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use curve() function without using x as the variable name inside expression?
On 31/01/15 21:10, C W wrote: Hi Bill, One quick question. What if I wanted to use curve() for a uniform distribution? Say, unif(0.5, 1.3), 0 elsewhere. My R code: func <- function(min, max){ 1 / (max - min) } curve(func(min = 0.5, max = 1.3), from = 0, to = 2) curve() wants an expression, but I have a constant. And I want zero everywhere else. Well if that's what you want, then say so!!! func <- function(x,min,max) { ifelse(x < min | x > max, 0, 1/(max - min)) } curve(func(u,0.5,1.3),0,2,xname="u") Or, better (?) curve(func(u,0.5,1.3),0,2,xname="u",type="s") which avoids the slight slope in the "vertical" lines. cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 Home phone: +64-9-480-4619 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] naming rows/columns in 'array of matrices' | solved
> On 30 Jan 2015, at 20:34 , Evan Cooch wrote: > > The (obvious, after the fact) solution at the bottom. D'oh... > [snip] > Forgot I was dealing with a multi-dimensional array, not a list. So, > following works fine. I'm sure there are better approaches (where 'better' is > either 'cooler', or 'more flexible'), but for the moment...) > > P <- array(0, c(2,2,2),dimnames=list(c("live","dead"),c("old","young"),NULL)) > > P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T); > P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T); > > print(P); > Just for completeness, this also works: > P <- array(0, c(2,2,2)) > P[,,1] <- matrix(c(1,2,3,4),2,2,byrow=T); > P[,,2] <- matrix(c(5,6,7,8),2,2,byrow=T); > dimnames(P)[[1]] <- c("live","dead") > dimnames(P)[[2]] <- c("live","dead") -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use curve() function without using x as the variable name inside expression?
Hi Bill, One quick question. What if I wanted to use curve() for a uniform distribution? Say, unif(0.5, 1.3), 0 elsewhere. My R code: func <- function(min, max){ 1 / (max - min) } curve(func(min = 0.5, max = 1.3), from = 0, to = 2) curve() wants an expression, but I have a constant. And I want zero everywhere else. Thanks, Mike On Thu, Jan 29, 2015 at 10:34 PM, C W wrote: > Hi Bill, > > You solved by problem. For some reason, I thought xname was only > referring to name of the x-axis. > > I remember last time I fixed it, it was something about xname, couldn't > get it right this time. > > Thanks! Saved me hours from frustration. > > Mike > > On Thu, Jan 29, 2015 at 9:04 PM, William Dunlap wrote: > >> Does >>help(curve) >> talk about its 'xname' argument? >> >> Try >>curve(10*foofoo, from=0, to=17, xname="foofoo") >> >> You will have to modify your function, since curve() will >> call it once with a long vector for the independent variable >> and func(rnorm(10), rnorm(10), mu=seq(0,5,len=501)) won't >> work right. >> >> >> Bill Dunlap >> TIBCO Software >> wdunlap tibco.com >> >> On Thu, Jan 29, 2015 at 5:43 PM, C W wrote: >> >>> Hi Rui, >>> >>> Thank you for your help. That works for now, but eventually, I need to >>> be >>> pass in x and y. >>> >>> Is there a way to tell the curve() function, x is a fix vector, mu is a >>> variable! >>> >>> Thanks, >>> >>> Mike >>> >>> On Thu, Jan 29, 2015 at 5:25 PM, Rui Barradas >>> wrote: >>> >>> > Hello, >>> > >>> > The following will work, but I don't know if it's what you want. func2 >>> > will get x and y from the global environment. >>> > >>> > func2 <- function(mu){ >>> >x + y + mu ^ 2 >>> > } >>> > >>> > curve(func2, from = 0, to = 10) >>> > >>> > >>> > Hope this helps, >>> > >>> > Rui Barradas >>> > >>> > Em 29-01-2015 21:02, C W escreveu: >>> > >>> >> Hi all, >>> >> >>> >> I want to graph a curve as a function of mu, not x. >>> >> >>> >> Here's the R code: >>> >> >>> >> x <- rnorm(10) >>> >> y <- rnorm(10) >>> >> >>> >> func <- function(x, y, mu){ >>> >> x + y + mu ^ 2 >>> >> } >>> >> >>> >> curve(f = func(x = x, y = y, mu), from = 0, to = 10) >>> >> I know I can change variable mu to x, but is there a way to tell R >>> that mu >>> >> is the variable of interest, not x. >>> >> >>> >> Thanks in advance, >>> >> >>> >> Mike >>> >> >>> >> [[alternative HTML version deleted]] >>> >> >>> >> __ >>> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> >> https://stat.ethz.ch/mailman/listinfo/r-help >>> >> PLEASE do read the posting guide http://www.R-project.org/ >>> >> posting-guide.html >>> >> and provide commented, minimal, self-contained, reproducible code. >>> >> >>> >> >>> >>> [[alternative HTML version deleted]] >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide >>> http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >> >> > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.