Re: [R] Help needed in double bar plot made using ggplot2
Thanks Dr. Burradas too. i also had the same question. regards August 20, 2021 6:02 AM, "bharat rawlley via R-help" wrote: > Thank you, Dr. Burradas! > That resolved my query > Have a great rest of your day > On Thursday, 19 August, 2021, 04:47:42 pm GMT-4, Rui Barradas > wrote: > __ 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] separate date and time
Schatzi cargill.com> writes: > > I have a combined date and time. I would like to separate them out into two > columns so I can do things such as take the mean by time across all dates. > > meas<-runif(435) > nTime<-seq(1303975800, 1304757000, 1800) > nDateT<-as.POSIXct(nTime, origin="1970-01-01") > mat1<-cbind(nDateT,meas) > > means1<- aggregate(mat1$meas, list(nDateT), mean) > > This doesn't do anything as each day is different, but if I had just the > time, it would take the mean outputing 48 values (for each 30 min). > > Also, sometimes there are missing meas to a specific time. Is there anyway > to copy the previous meas if one is missing? > > - > In theory, practice and theory are the same. In practice, they are not - Albert Einstein > -- > View this message in context: http://r.789695.n4.nabble.com/separate-date-and-time-tp3517571p3517571.html > Sent from the R help mailing list archive at Nabble.com. > > Not sure if this is what you want, but you can use substr to split nDateT into date and time, and then use aggregate() in the time column in df1. meas<-runif(435) nTime<-seq(1303975800, 1304757000, 1800) nDateT<-as.POSIXct(nTime, origin="1970-01-01") date <- substr(nDateT, 1, 10) time <- substr(nDateT, 12, 19) df1 <- data.frame(date, time, meas) means1<- aggregate(df1$meas, list(df1$time), mean) HTH, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Changing x-axis when dealing with time
Pablo Rosado lbl.gov> writes: > > Hi, > > I am plotting data in which the x values are a timestamp. I am trying to > change the x-ticks so they will be in specified hours of the day, but it > always start from hour 4 of the day. And I need it to start from the > beginning of the axis (at x=0) and then each tick be on the interval I > specify. > > Here is my plotting script: > > *##-- ROOF COMPARISON - SOUTH-- > win.graph() > plot(x=tiempo,y=timeframe[,8],xlab="",ylab="",**xaxt='n',** > yaxt='n',type="l",col="blue",lwd=3,ylim=c(0,80),font=2,las=1) > axis(side=1,at=seq(0,24,3)) > axis(side=2,at=seq(0,80,10),line=NA, tcl = -0.5,font=2,las=1) > lines(x=tiempo,y=timeframe[,47],col="red",lwd=3) > title(xlab=paste("Local Standard Time (",date), cex.lab=1,font.lab=2) > title(ylab="Temperature (°C)", cex.lab=1,font.lab=2) > legend("topleft",legend=c("cool", "standard"),col=c("blue", > "red"),lwd=c(4,4),bty="n",cex=1.25) > grid(nx=NULL,ny=NULL,col = "gray", lty = "dotted",lwd = 1)* > > But with the axis(side=1...) nothing appears. > > I have been practicing with the following code to change the xaxis but it > says that x and y lengths differ: > > *## TIMESTAMP IS A ONE COLUMN VECTOR IN WHICH I SAVED THE TIMESTAMP FROM MY > FILE > string.to.time <- > function(timestamp) > strptime(x=timestamp, format="%Y-%m-%d %H:%M:%S") > > decimal.day <- > function(timestamp) { > y <- as.POSIXlt(**timestamp**) > y$day + y$hour/24 + y$min/(24*60) + y$sec/(24*60*60) > } > > decimal.hour <- > function(**timestamp**) { > dd <- decimal.day(**timestamp**) > 24 * (dd - floor(dd)) > } > > ##create some data to plot > t.start <- string.to.time("2011-05-02 00:00:00") > t.start > t.vector <- t.start + (0:24)*3600 > t.vector > z.vector <- 1:length(t.vector) > z.vector > > ##vector of decimal hours > dh.vector <- decimal.hour(t.vector) > dh.vector > > plot(x=dh.vector, y=z.vector, xlim=c(0,24), xaxt="n", xlab="Hour of day", > ylab="Some property") > * > > Thank You so much and have a great weekend. > Hi Pablo, I'm a big fan of the "chron" package for plotting dates on axis. Not sure if this is what you are looking for,but might be helpful. Here is a simple example using the chron package and plotting dates on x-axis. You can alter the text labels on x-axis using substr() on the date vector. # create "chron" time vector library(chron) excel.dates <- seq(40179.0 + 1/6, 40180.0 + 1/6, 1/6) orig <- chron("12/30/1899") date.time <- orig + excel.dates; time.only <- substr(date, 11, 18) # Y data y.dat = rnorm(7, 10, 3) # Plot it up! Don't add annotations or axes for now plot(date.time, y.dat, type="n", ann=F, axes=F) # Add data lines(date.time, y.dat, lwd = 2, col = "black") points(date.time, y.dat, pch = 20, col = "magenta") box() # add box around plot # Add X-Axis and label axis(1, at=c(seq(date.time[1], date.time[length(date.time)],1/6)), tck = +0.01, labels = F) #label=date.time # prints date and time label = time.only # only prints time x.len=length(label) text(x=date.time[1:x.len], par("usr")[3]-.135, srt = 45, adj = 1, labels = label, xpd = T) mtext(side = 1, "Time", line = 3.2) #X-axis label HTH, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Changing x-axis when dealing with time
Ken bu.edu> writes: > # create "chron" time vector > library(chron) > excel.dates <- seq(40179.0 + 1/6, 40180.0 + 1/6, 1/6) > orig <- chron("12/30/1899") > date.time <- orig + excel.dates; > time.only <- substr(date, 11, 18) Found one error in my script above. Correction: time.only <- substr(date.time, 11, 18) Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using a sting in variable names
olafgy gmail.com> writes: > > Hi there, > > I am trying to import 100 files with the names of "vpn 1 .dat" to "vpn 100 > .dat" > into a respective table calld vpn1 to vpn100. > > I therfore have created a variable X<-1:100 > > I not want to use X as a subtitute for the number in my filename, so that I > have to write only one function and it does the operation with all files. > > I have tried every combination i could imagine to include the string X into > the file name: > > vpn'X' , vpn"X" , vpn[X] , and so on, but R never did what I wanted it > too. > > vpn"X"<-read.table("vpn "X" .dat") > > So is there a way to do this in R??? or should I use an intirely new > aproach? > > Thanks for your Help! > > -- > View this message in context: http://r.789695.n4.nabble.com/Using-a-sting-in-variable-names-tp3527318p3527318.html > Sent from the R help mailing list archive at Nabble.com. > > why don't you use a list (?list)? This is particularly useful if each file is formatted in the same way (ie. if they have the same columns, in the same order, etc.), but this is not a necessity. Read each file as an separate item in the list. That way if you want to compute the same statistic on each of your files, you can use lapply on the each item of the list. I think this way save memory, but not totally sure on it. Example: X <- 1:100 vpn <- vector(mode = "list", length = length(X)) for(i in 1:length(X)){ vpn[[i]] <- read.table(paste("vpn", X[i], ".dat", sep ="")) } HTH, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] slow computation of functions over large datasets
Sorry about the lack of code, but using Davids example, would: tapply(itemPrice, INDEX=orderID, FUN=sum) work? -Ken Hutchison On Aug 3, 2554 BE, at 2:09 PM, David Winsemius wrote: > > On Aug 3, 2011, at 2:01 PM, Ken wrote: > >> Hello, >> Perhaps transpose the table attach(as.data.frame(t(data))) and use ColSums() >> function with order id as header. >>-Ken Hutchison > > Got any code? The OP offered a reproducible example, after all. > > -- > David. >> >> On Aug 3, 2554 BE, at 1:12 PM, David Winsemius >> wrote: >> >>> >>> On Aug 3, 2011, at 12:20 PM, jim holtman wrote: >>> >>>> This takes about 2 secs for 1M rows: >>>> >>>>> n <- 100 >>>>> exampledata <- data.frame(orderID = sample(floor(n / 5), n, replace = >>>>> TRUE), itemPrice = rpois(n, 10)) >>>>> require(data.table) >>>>> # convert to data.table >>>>> ed.dt <- data.table(exampledata) >>>>> system.time(result <- ed.dt[ >>>> + , list(total = sum(itemPrice)) >>>> + , by = orderID >>>> + ] >>>> +) >>>> user system elapsed >>>> 1.300.051.34 >>> >>> Interesting. Impressive. And I noted that the OP wanted what cumsum would >>> provide and for some reason creating that longer result is even faster on >>> my machine than the shorter result using sum. >>> >>> -- >>> David. >>>>> >>>>> str(result) >>>> Classes ‘data.table’ and 'data.frame': 198708 obs. of 2 variables: >>>> $ orderID: int 1 2 3 4 5 6 8 9 10 11 ... >>>> $ total : num 49 37 72 92 50 76 34 22 65 39 ... >>>>> head(result) >>>> orderID total >>>> [1,] 149 >>>> [2,] 237 >>>> [3,] 372 >>>> [4,] 492 >>>> [5,] 550 >>>> [6,] 676 >>>>> >>>> >>>> >>>> On Wed, Aug 3, 2011 at 9:25 AM, Caroline Faisst >>>> wrote: >>>>> Hello there, >>>>> >>>>> >>>>> I’m computing the total value of an order from the price of the order >>>>> items >>>>> using a “for” loop and the “ifelse” function. I do this on a large >>>>> dataframe >>>>> (close to 1m lines). The computation of this function is painfully slow: >>>>> in >>>>> 1min only about 90 rows are calculated. >>>>> >>>>> >>>>> The computation time taken for a given number of rows increases with the >>>>> size of the dataset, see the example with my function below: >>>>> >>>>> >>>>> # small dataset: function performs well >>>>> >>>>> exampledata<-data.frame(orderID=c(1,1,1,2,2,3,3,3,4),itemPrice=c(10,17,9,12,25,10,1,9,7)) >>>>> >>>>> exampledata[1,"orderAmount"]<-exampledata[1,"itemPrice"] >>>>> >>>>> system.time(for (i in 2:length(exampledata[,1])) >>>>> {exampledata[i,"orderAmount"]<-ifelse(exampledata[i,"orderID"]==exampledata[i-1,"orderID"],exampledata[i-1,"orderAmount"]+exampledata[i,"itemPrice"],exampledata[i,"itemPrice"])}) >>>>> >>>>> >>>>> # large dataset: the very same computational task takes much longer >>>>> >>>>> exampledata2<-data.frame(orderID=c(1,1,1,2,2,3,3,3,4,5:200),itemPrice=c(10,17,9,12,25,10,1,9,7,25:220)) >>>>> >>>>> exampledata2[1,"orderAmount"]<-exampledata2[1,"itemPrice"] >>>>> >>>>> system.time(for (i in 2:9) >>>>> {exampledata2[i,"orderAmount"]<-ifelse(exampledata2[i,"orderID"]==exampledata2[i-1,"orderID"],exampledata2[i-1,"orderAmount"]+exampledata2[i,"itemPrice"],exampledata2[i,"itemPrice"])}) >>>>> >>>>> >>>>> >>>>> Does someone know a way to increase the speed? >>>>> >>>>> >>>>> Thank you very much! >>>>> >>>>> Caroline >>>>> >>>>> [[alternative HTML version deleted]] >>>>> >>>>> >>>>> __ >>>>> R-help@r-project.org mailing list >>>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>>> PLEASE do read the posting guide >>>>> http://www.R-project.org/posting-guide.html >>>>> and provide commented, minimal, self-contained, reproducible code. >>>>> >>>>> >>>> >>>> >>>> >>>> -- >>>> Jim Holtman >>>> Data Munger Guru >>>> >>>> What is the problem that you are trying to solve? >>>> >>>> __ >>>> R-help@r-project.org mailing list >>>> https://stat.ethz.ch/mailman/listinfo/r-help >>>> PLEASE do read the posting guide >>>> http://www.R-project.org/posting-guide.html >>>> and provide commented, minimal, self-contained, reproducible code. >>> >>> David Winsemius, MD >>> West Hartford, CT >>> >>> __ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. > > David Winsemius, MD > West Hartford, CT > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] slow computation of functions over large datasets
Hello, Perhaps transpose the table attach(as.data.frame(t(data))) and use ColSums() function with order id as header. -Ken Hutchison On Aug 3, 2554 BE, at 1:12 PM, David Winsemius wrote: > > On Aug 3, 2011, at 12:20 PM, jim holtman wrote: > >> This takes about 2 secs for 1M rows: >> >>> n <- 100 >>> exampledata <- data.frame(orderID = sample(floor(n / 5), n, replace = >>> TRUE), itemPrice = rpois(n, 10)) >>> require(data.table) >>> # convert to data.table >>> ed.dt <- data.table(exampledata) >>> system.time(result <- ed.dt[ >> + , list(total = sum(itemPrice)) >> + , by = orderID >> + ] >> +) >> user system elapsed >> 1.300.051.34 > > Interesting. Impressive. And I noted that the OP wanted what cumsum would > provide and for some reason creating that longer result is even faster on my > machine than the shorter result using sum. > > -- > David. >>> >>> str(result) >> Classes ‘data.table’ and 'data.frame': 198708 obs. of 2 variables: >> $ orderID: int 1 2 3 4 5 6 8 9 10 11 ... >> $ total : num 49 37 72 92 50 76 34 22 65 39 ... >>> head(result) >>orderID total >> [1,] 149 >> [2,] 237 >> [3,] 372 >> [4,] 492 >> [5,] 550 >> [6,] 676 >>> >> >> >> On Wed, Aug 3, 2011 at 9:25 AM, Caroline Faisst >> wrote: >>> Hello there, >>> >>> >>> I’m computing the total value of an order from the price of the order items >>> using a “for” loop and the “ifelse” function. I do this on a large dataframe >>> (close to 1m lines). The computation of this function is painfully slow: in >>> 1min only about 90 rows are calculated. >>> >>> >>> The computation time taken for a given number of rows increases with the >>> size of the dataset, see the example with my function below: >>> >>> >>> # small dataset: function performs well >>> >>> exampledata<-data.frame(orderID=c(1,1,1,2,2,3,3,3,4),itemPrice=c(10,17,9,12,25,10,1,9,7)) >>> >>> exampledata[1,"orderAmount"]<-exampledata[1,"itemPrice"] >>> >>> system.time(for (i in 2:length(exampledata[,1])) >>> {exampledata[i,"orderAmount"]<-ifelse(exampledata[i,"orderID"]==exampledata[i-1,"orderID"],exampledata[i-1,"orderAmount"]+exampledata[i,"itemPrice"],exampledata[i,"itemPrice"])}) >>> >>> >>> # large dataset: the very same computational task takes much longer >>> >>> exampledata2<-data.frame(orderID=c(1,1,1,2,2,3,3,3,4,5:200),itemPrice=c(10,17,9,12,25,10,1,9,7,25:220)) >>> >>> exampledata2[1,"orderAmount"]<-exampledata2[1,"itemPrice"] >>> >>> system.time(for (i in 2:9) >>> {exampledata2[i,"orderAmount"]<-ifelse(exampledata2[i,"orderID"]==exampledata2[i-1,"orderID"],exampledata2[i-1,"orderAmount"]+exampledata2[i,"itemPrice"],exampledata2[i,"itemPrice"])}) >>> >>> >>> >>> Does someone know a way to increase the speed? >>> >>> >>> Thank you very much! >>> >>> Caroline >>> >>> [[alternative HTML version deleted]] >>> >>> >>> __ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/r-help >>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >>> and provide commented, minimal, self-contained, reproducible code. >>> >>> >> >> >> >> -- >> Jim Holtman >> Data Munger Guru >> >> What is the problem that you are trying to solve? >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. > > David Winsemius, MD > West Hartford, CT > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Convert matrix to numeric
How about Matrix[1:5,]=as.numeric(Matrix[1:5,]) -Ken Hutchison On Aug 3, 2554 BE, at 3:04 PM, Jeffrey Joh wrote: > > I have a matrix that looks like this: > > > structure(c("0.0376673981759913", "0.111066500741386", "1", "1103", > "18", "OPEN", "DEPR", "0.0404073656092023", "0.115186044704599", > "1", "719", "18", "OPEN", "DEPR", "0.0665342096693433", "0.197570061769498", > "1", "1103", "18", "OPEN", "DEPR", "0.119287147905722", "0.356427096010845", > "1", "1103", "18", "OPEN", "DEPR"), .Dim = c(7L, 4L), .Dimnames = list( >c("Sn", "SlnC", "housenum", "date", "hour", "flue", "pressurization" >), c("10019.BLO", "1002.BLO", "10020.BLO", "10021.BLO"))) > > > > How do I convert rows 1-5 to numeric? I tried mode() <- "numeric" but that > doesn't change anything. > > > > I also tried converting this to a table then converting to numeric, but I > got: (list) object cannot be coerced to type 'double' > > > > Jeff > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Installing R-Packages from zipp file
If you have an Internet connection try: > install.packages("copula", dep=TRUE) Good luck! Ken On Aug 6, 2554 BE, at 8:44 AM, poulomi wrote: > Hi, > > I'm a new user of R. I want to install 'copula' packages. I downloaded the > package and from the tab above in R-console i selected "install packages > from Zipped file". After this when I 'm writing in a command prompt > library(copula). It gives the error massage as > Error in library(copula) : 'copula' is not a valid installed package. > > I'm not sure how to install the package. Any help will be appreciable. > > -- > View this message in context: > http://r.789695.n4.nabble.com/Installing-R-Packages-from-zipp-file-tp3723275p3723275.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.
Re: [R] Automating an R function call
Hey, Sys.sleep(300) ?Sys.sleep Ken Hutchison On Aug 12, 2554 BE, at 2:03 PM, RobertJK wrote: > Any way to run an R function every 5 minutes from the R terminal? Searched > around but couldn't find any answers. Thanks!! > Robert > > -- > View this message in context: > http://r.789695.n4.nabble.com/Automating-an-R-function-call-tp3740070p3740070.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.
Re: [R] seeking advice about rounding error and %%
How about something like: If(round(x)!=x){zap} not exactly working code but might help Ken On Aug 13, 2554 BE, at 3:42 PM, Paul Johnson wrote: > A client came into our consulting center with some data that had been > damaged by somebody who opened it in MS Excel. The columns were > supposed to be integer valued, 0 through 5, but some of the values > were mysteriously damaged. There were scores like 1.18329322 and such > in there. Until he tracks down the original data and finds out what > went wrong, he wants to take all fractional valued scores and convert > to NA. > > As a quick hack, I suggest an approach using %% > >> x <- c(1,2,3,1.1,2.12131, 2.001) >> x %% 1 > [1] 0.0 0.0 0.0 0.1 0.12131 0.00100 >> which(x %% 1 > 0) > [1] 4 5 6 >> xbad <- which(x %% 1 > 0) >> x[xbad] <- NA >> x > [1] 1 2 3 NA NA NA > > I worry about whether x %% 1 may ever return a non zero result for an > integer because of rounding error. > > Is there a recommended approach? > > What about zapsmall on the left, but what on the right of >? > > which( zapsmall(x %% 1) > 0 ) > > > Thanks in advance > > -- > Paul E. Johnson > Professor, Political Science > 1541 Lilac Lane, Room 504 > University of Kansas > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Test for Random Walk and Makov Process
For random walk, there are entropy based tests (Robinson 1991), or you could empirically test the hypothesis by generating random normal data with the same mean and standard deviation and looking at the distribution of your quantiles. You could make generic statements also about whether or not the data demonstrates autocorrelation function values which are not significant and do not appear to have trend. Further, In a random walk, a binary variable for whether or not values are above and below the mean should follow a binomial distribution of size 1 with a probability of .5, there are tests which do this but also take magnitude into account. I mean to say there are a lot of ways to approach that problem, it depends on the application and how strong you want your conclusions to be. What kind of Markov process? On Sep 3, 2554 BE, at 9:59 PM, Jumlong Vongprasert wrote: > Dear All > I want to test my data for Random Walk or Markov Process. > How I can do this. > Many Thanks > > -- > Jumlong Vongprasert Assist, Prof. > Institute of Research and Development > Ubon Ratchathani Rajabhat University > Ubon Ratchathani > THAILAND > 34000 > >[[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] Generating data when mean and 95% CI are known
R can tell you how many possible answers there are with those givens though: ?Inf Really though, you can get at some information if you are willing to set one of those definitively. I.e. If you set sample size you can 'find' data which match specs but isn't going to be applicable to anything because there is probably more to the story distributionally. If you can assume, say a normal distribution you are ?rnorm and ?quantile away from Monte Carlo-ing a good part of the story yourself for conclusions. Best of luck, and sorry for the bad R jokes. Ken Hutchison On Sep 7, 2554 BE, at 10:22 PM, Rolf Turner wrote: > On 08/09/11 09:51, Tyler Hicks wrote: >> Is there a function in R that will generate data from a known mean and 95% >> CI? I do not know the distribution or sample size of the original data. > > No. R is wonderful, but it cannot work magic. > >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.
Re: [R] how to remove NA/NaN/Inf in a matrix??
Try: library(Hmisc) ?na.delete Ken Hutchison On Sep 11, 2554 BE, at 5:38 AM, anand m t wrote: > Hi all.. > I'm very new R, and i'm analyzing microarray data using Bioconductor.. > Recently i was given microarray data to analyze. The problem is whenever i > run MAS5 presence calls algorithm, > it throws an error saying NA/NaN/Inf in foreign function. How do i remove > such NA/NaN/Inf's ?? > I tried na.omit(dataframe) but stil problem exists. > > dimension of matrix (data) is 35556 7. > >> data.mas5calls=mas5calls(data) > Getting probe level data... > Computing p-values > Error in FUN(1:6[[1L]], ...) : > NA/NaN/Inf in foreign function call (arg 2) > > Thank you. > > -- > ** > Anand M.T > School of Biotechnology (Bio-Informatics), > International Instituteof Information Technology (I2IT), > P-14, Rajiv Gandhi Infotech park, > Hinjewadi, > Pune-411 057. > INDIA. > > "The secret of success comprised in three words.. Work, Finish & Publish" - > Michael Faraday > >[[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] Where to put tryCatch or similar in a very big for loop
What type of singularity exactly, if you're working with counts is it a special case? If using a Monte Carlo generation scheme, there are various workarounds such as while(sum(vec)!=0) {sample} for example. More info on the error circumstances would help. Good luck! Ken Hutchison On Sep 15, 2554 BE, at 11:41 AM, "Bonnett, Laura" wrote: > Hi Steve, > > Thanks for your response. The slight issue is that I need to use a different > starting seed for each simulation. If I use 'lapply' then I end up using the > same seed each time. (By contrast, I need to be able to specify which > starting seed I am using). > > Thanks, > Laura > > -Original Message- > From: Steve Lianoglou [mailto:mailinglist.honey...@gmail.com] > Sent: 15 September 2011 16:17 > To: Bonnett, Laura > Cc: r-help@r-project.org > Subject: Re: [R] Where to put tryCatch or similar in a very big for loop > > Hi Laura, > > On Thu, Sep 15, 2011 at 10:53 AM, Bonnett, Laura > wrote: >> Dear all, >> >> I am running a simulation study to test variable imputation methods for Cox >> models using R 2.9.0 and Windows XP. The code I have written (which is >> rather long) works (if I set nsim = 9) with the following starting values. >> >>> bootrs(nsim=9,lendevdat=1500,lenvaldat=855,ac1=-0.19122,bc1=-0.18355,cc1=-0.51982,cc2=-0.49628,eprop1=0.98,eprop2=0.28,lda=0.003) >> >> I need to run the code 1400 times in total (bootstrap resampling) however, >> occasionally the random numbers generated lead to a singularity and hence >> the code crashes as one of the Cox model cannot be fitted (the 10th >> iteration is the first time this happens). >> >> I've been trawling the internet for ideas and it seems that there are >> several options in the form of try() or tryCatch() or next. I'm not sure >> however, how to include them in my code (attached). Ideally I'd like it to >> run everything simulation from 1 to 1400 and if there is an error at some >> point get an error message returned (I need to count how many there are) but >> move onto the next number in the loop. >> >> I've tried putting try(,silent=TRUE) around each cox model (cph >> statement) but that hasn't work and I've also tried putting try around the >> whole for loop without any success. > > Let's imagine you are using an `lapply` instead of `for`, only because > I guess you want to store the results of `bootrs` somewhere, you can > adapt this to your `for` solution. I typically return NULL when an > error is caught, then filter those out from my results, or whatever > you like: > > results <- lapply(1:1400, function(i) { > tryCatch(bootrs(...whatever...), error=function(e) NULL) > }) > went.south <- sapply(results, is.null) > > The `went.south` vector will be TRUE where an error occurred in your > bootrs call. > > HTH, > -steve > > -- > Steve Lianoglou > Graduate Student: Computational Systems Biology > | Memorial Sloan-Kettering Cancer Center > | Weill Medical College of Cornell University > Contact Info: http://cbio.mskcc.org/~lianos/contact > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Limitations of audio processing in R
Also with Linux you can add more swap memory(which I'm pretty sure R spills into if it hasn't reached it's internal limits on 32 bit installations). Windows pagefile is kind of obnoxious. Ken Hutchison On Sep 21, 2554 BE, at 5:05 PM, (Ted Harding) wrote: > Hi Ulisses! > Yes, "get more creative" -- or "get more memory"! > > On the "creative" side, it may be worth thinking about > using an independent (non-R) audio file editor. I'm > writing from the standpoint of a Linux/Unixoid user > here -- I wouldn;t know how to set ebout this in WIndows. > > You could use R to create a shell script which would run > the editor in such a way as to extract your 6 random samples, > and save them, where the script would be fed with the > randomly-chosen 5-minute intervals decided by R. This > could be done under the control of R, so you could set > it up for your 1500 or so sets of samples, which (with > the right editing program) could be done quite quickly. > > On Linux (also available for Windows) a flexible audio > editor is 'sox' -- see: > > http://en.wikipedia.org/wiki/SoX > > To take, say, a 5-minute sample starting at 1 hour, > 10 min and 35sec into the audio file "infile.wav", > and save this as "outfile.wav", you can execute > > sox infile.wav outfile.wav trim 01:10:35 00:05:00 > > and such a command could easily be generated by R and > fed to a shell script (or simply executed from R by > using the system() command). My test just now with > a 5-minute long sample from a .wav file was completed > in about 5 seconds, so it is quite efficient. > > There is a huge number of options for 'sox', allowing > you to manipulate almost any aspect of the editing. > > Hoping this helps, > Ted. > > > On 21-Sep-11 19:55:22, R. Michael Weylandt wrote: >> If you are running Windows it may be as simple as using >> memory.limit() to allow R more memory -- if you are on >> another OS, it may be possible to get the needed memory >> by deleting various things in your workspace and running >> gc() >> >> Of course, if your computer's memory is <3GB, you are >> probably going to have trouble with R's keeping all objects >> in memory and will have to get more creative. >> >> Michael >> >> On Wed, Sep 21, 2011 at 3:43 PM, Ulisses.Camargo < >> moliterno.cama...@gmail.com> wrote: >> >>> Hello everybody >>> >>> I am trying to process audio files in R and had some problems >>> with files size. I´m using R packages 'audio' and 'sound'. >>> I´m trying a really simple thing and it is working well with >>> small sized .wav files. When I try to open huge audio files >>> I received this error message: "cannot allocate vector of >>> size 2.7 Gb". My job is open in R a 3-hour .wav file, make six >>> 5-minute random audio subsamples, and than save these new files. >>> I have to do the same process +1500 times. My problems is not >>> in build the function to do the job, but in oppening the 3-hour >>> files. Does anybody knows how to handle big audio files in R? >>> Another package that allows me to do this work? I believe >>> this is a really simple thing, but I really don´t know what >>> to do to solve that memory problem. >>> >>> Thank you very much for your answers, >>> all the best! >>> >>> Ulisses > > > E-Mail: (Ted Harding) > Fax-to-email: +44 (0)870 094 0861 > Date: 21-Sep-11 Time: 22:05:55 > -- XFMail -- > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] interpolation to montly data
stef salvez googlemail.com> writes: > > I would like to clarify that since each observation is obtained every > 28 days, each such observation is a 4-week average > > thanks > > On 6/16/12, stef salvez googlemail.com> wrote: > > I have a panel data set (in MS excel) like the one below > > > > > > 1 "23/11/08"2 > > 1 "28/12/08" 3 > > 1"25/01/09" 4 > > 1 "22/02/09" 5 > > 1"29/03/09" 6 > > 1 "26/04/09" 32 > > 1 "24/05/09" 23 > > 1 "28/06/09" 32 > > 2 "26/10/08"45 > > 2 "23/11/08" 46 > > 2 "21/12/08" 90 > > 2 "18/01/09"54 > > 2 "15/02/09" 65 > > 2 "16/03/09" 77 > > 2 "12/04/09"7 > > 2 "10/05/09" 6 > > > > > > > > > > the start and end date of the time series for countries 1 and 2 are > > different. For example, for country 1 the time series begins on > > "23/11/08" while for country 2 the time series begins on "26-10-2008”. > > > > My data on prices are available every 28 days (or equivalently every 4 > > weeks). But in some cases I have jumps (35 days or 29 days instead of > > 28 days). For example from the above table we have such jumps: from > > "28/12/08" to "28/12/08" , from 22/02/09" to "29/03/09", etc > > > > My goal is to have a unified sequence of dates across countries. So, > > to achieve this I want to apply the following solutions > > > > I want to take what I have and calculate monthly average prices and also > > report how many prices those averages are based on. I suppose that I > > will still have gaps and may well need to interpolate. > > > > Please, I would be grateful to you if you could provide the exact code > > for doing this > > > > > > thanks a lot > > > > __ > R-help r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Hi Stef, I'm a little confused on how you want to break up the values in "4 week" bins, but if you wanted to keep it simple and do averages according to the month they fall in you could use the plyr package with a custom utility function: #load library library(plyr) # utility function mean.var = function(df, var){ mean(df[[var]], na.rm = T)}; # create example data dat <- data.frame("country" = c(rep(1,8), rep(2, 8)), "date" = c("23/11/08","28/12/08","25/01/09","22/02/09", "29/03/09","26/04/09","24/05/09", "28/06/09", "26/10/08","23/11/08","21/12/08","18/01/09", "15/02/09","16/03/09","12/04/09","10/05/09"), "price" = c(2,3,4,5,6,32,23,32,45,46,90,54,65,77,7,6)) # add month column to df dat$month = substr(dat$date, 4,5) #calculate average price by month across all countries and calculate monthly #frequency and put output in one data frame monthly.price = ddply(dat, .(month), mean.var, var = "price") monthly.price = cbind(monthly.price, "month.freq" = as.vector(table(df$month))) names(monthly.price) = c("month", "average.price", "month.freq") HTH, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] append to PDF file
PDF files contain information at the end of them and so you cannot append without altering the file (universally true for PDF). Perhaps pdf() your plots and use external tools to convert the PDFs to .ps then re-merge. Might not be the best way, but an effective one. Ken Hutchison On Nov 26, 2554 BE, at 5:38 PM, Christof Kluß wrote: > Hi > > is there a way to append a plot as PDF to an existing PDF file? > savePlot seems not to have this possibility. > > Christof > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Question about randomForest
I am pretty sure that when each tree is fitted the error rate for tree 'i' is it's performance on the data which was not used to fit the ith tree (OOB). In this way cross validation is performed for each tree but I do not think that all trees fitted prior are involved in the computation of that error. The idea (I think) is that if enough trees are fitted to randomly selected data, the phenomenon of overfitting will die out when you use the voting system and the error out of sample will approximate the average of the out of sample performance for all trees individually. If plotting the error by number of trees for example, I think the function plots the average of the oob errors by tree up until tree i. The reason I suspect this is because if you were handed a forest with the data used to create it, there would be no meaningful way to detect how well it would perform out of sample without getting at the error for each tree out of sample. This seems the most 'honest' option si! nce using all trees up until tree i could be misleading (and outlier prone) due to uneven sampling with a small number of replications, not to mention earlier trees would get more votes on the error. Please correct me if I am wrong, Hopefully a specialist will come along and clear this up, Ken Hutchison On Nov 27, 2554 BE, at 3:21 AM, Matthew Francis wrote: > Thanks for the help. Let me explain in more detail how I think that > randomForest works so that you (or others) can more easily see the > error of my ways. > > The function first takes a random sample of the data, of the size > specified by the sampsize argument. With this it fully grows a tree > resulting in a horribly over-fitted classifier for the random sub-set. > It then repeats this again with a different sample to generate the > next tree and so on. > > Now, my understanding is that after each tree is constructed, a test > prediction for the *whole* training data set is made by combining the > results of all trees (so e.g. for classification the majority votes of > all individual tree predictions). From this an error rate is > determined (applicable to the ensemble applied to the training data) > and reported in the err.rate member of the returned randomForest > object. If you look at the error rate (or plot it using the default > plot method) you see that it starts out very high when only 1 or a few > over-fitted trees are contributing, but once the forest gets larger > the error rate drops since the ensemble is doing its job. It doesn't > make sense to me that this error rate is for a sub-set of the data, > since the sub-set in question changes at each step (i.e. at each tree > construction)? > > By doing cross-validation test making 'training' and 'test' sets from > the data I have, I do find that I get error rates on the test sets > comparable to the error rate that is obtained from the prediction > member of the returned randomForest object. So that does seem to be > the 'correct' error. > > By my understanding the error reported for the ith tree is that > obtained using all trees up to and including the ith tree to make an > ensemble prediction. Therefore the final error reported should be the > same as that obtained using the predict.randomForest function on the > training set, because by my understanding that should return an > identical result to that used to generate the error rate for the final > tree constructed?? > > Sorry that is a bit long winded, but I hope someone can point out > where I'm going wrong and set me straight. > > Thanks! > > On Sun, Nov 27, 2011 at 11:44 AM, Weidong Gu wrote: >> Hi Matthew, >> >> The error rate reported by randomForest is the prediction error based >> on out-of-bag OOB data. Therefore, it is different from prediction >> error on the original data since each tree was built using bootstrap >> samples (about 70% of the original data), and the error rate of OOB is >> likely higher than the prediction error of the original data as you >> observed. >> >> Weidong >> >> On Sat, Nov 26, 2011 at 3:02 PM, Matthew Francis >> wrote: >>> I've been using the R package randomForest but there is an aspect I >>> cannot work out the meaning of. After calling the randomForest >>> function, the returned object contains an element called prediction, >>> which is the prediction obtained using all the trees (at least that's >>> my understanding). I've checked that this prediction set has the error >>> rate as reported by err.rate. >>> >>> However, if I send the training data back into the the >>> predict.randomForest function I f
Re: [R] window manager interface commands for linux
Have not found a way to do this either, or in any case it has been buggy. It would depend on the file manager you have installed. But, you're using Linux! The path and working directory are supposed to be half the fun. Maybe create an R folder in /home to keep your files and adjust your R terminal settings so that organization and dir() will get you what you want. Hope that helps, Ken Hutchison On Nov 28, 2554 BE, at 6:07 AM, Ana wrote: > How can i replicate this in Linux: > source(file.choose()) > > > I've tried source(tkgetOpenFile()) but with no luck > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Principal componet plot from lower triangular matrix file
R distance objects are triangular, maybe consider as.dist() that would require the square matrix as input. Which could be reconstructed(or you have it already.) I do not know if there is a biglm() alternative to princomp(), but maybe consider using subsets of your data because that plot, if created, is going to be very hectic. HTH Ken Hutchison On Nov 28, 2554 BE, at 5:55 AM, cm wrote: > Hi, > > I have a comma separated file with element names in first column like shown > below : > > Name_1,0 > Name_2,0.8878,0 > Name_3,0.6777,0.7643,0 > Name_4,0.9844,0.1234,0.1414,0 > > Original data is a 1x1 symmetric matrix (600 MB). To reduce file > size, I have minimized matrix to only lower triangle. Is there a (memory) > efficient way to 1) read file 2) compute first and second principal > components and 3) and plot first vs second PC's ? > > In the past, I could do this by : > b <- read.csv("distance.csv", sep=",", head=F) # distance.csv file is > complete data matrix, so this command worked !! > my_matrix <- data.matrix(b) > pca2 <- princomp(my_matrix) > plot(pca2$scores[,1],pca2$scores[,2]) > text(pca2$scores[,1],pca2$scores[,2],rownames(nba_matrix), cex=0.5, pos=1) > > This time, I don't have a complete file. So, I was wondering, how to do this > ? > > Any help is much appreciated > > TIA > M > > -- > View this message in context: > http://r.789695.n4.nabble.com/Principal-componet-plot-from-lower-triangular-matrix-file-tp4114840p4114840.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.
Re: [R] Help with the Mice Function
Try reducing the maximum iterations. Probably won't make your call instantaneous, but might be worth the slack gained over a day or so. Ken Hutchison On Dec 9, 2554 BE, at 1:59 PM, "Richard J. Buning" wrote: > Hi, > > I am attempting to impute my data for missing values using the mice > function. However everytime I run the function it freezes or lags. > > I have tried running it over night, and it still does not finish. I am > working with 17000 observations across 32 variables. > > here is my code: > > imputed.data = mice(data, > + m = 1, + diagnostics = F) > > Thank you in advance, > > Richard > >[[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] fgrep with caret (^) meta-character in system() call
man awk? I've used awk for similar tasks (if I am reading the post correctly.) Google-Fu should turn up some useful examples. Also awk should be on your linux installation in some form or another. Regards, Ken Hutchison On Oct 4, 2554 BE, at 10:52 PM, "Tom D. Harray" wrote: > Hi there, > > I would like to use my linux system's fgrep to search for a text pattern > in a file. Calling system with > >system("fgrep \"SearchPattern\" /path/to/the/textFile.txt") > > works in general, but I need to search for the search pattern at the > beginning of the line. > > The corresponding shell command > >fgrep "^SearchPattern" /path/to/the/textFile.txt > | > |___ here's my problem > > does exactly what I want. I tried various combinations on ", \", \^, but > failed to make system() work. > > How can I call the working shell command including the caret > meta-character with system()? > > Thanks and regards, > > dirk > > > P.S.: Actually I have to search for about 5.000 patterns, stored in an R > list, in a text file with about 30.000.000 lines. The patterns appear in > one or more lines of the text file. Only those lines have to be > extracted if the patterns at the beginning of the line. > > Example with matching line 1, non matching line 2, non-matching line 3 > (line three comprises aaa, but not at the beginning of the line 3): > > SearchPattern = "^aaa" > > Text file:aaaooo >bbbiii >aacaaa > > Going line by line through the file in R is too slow, and I cannot > program it in C or C++. Hence I use the fgrep command. I would > appreciate if anyone has a fast alternative which works with R on Linux > and Windows systems. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Perform 20 x one-way anova in 1 go
Hey, Doesn't this give you a ridiculous Type 1 error? Maybe randomly select one result and trust it. Try bestglm or stepwise regression maybe. Hope that's helpful, Ken Hutchison On Oct 14, 2554 BE, at 12:39 AM, "C.H." wrote: > This is one solution > > ?sapply > > sapply(data.frame(iris$Sepal.Length, iris$Sepal.Width, > iris$Petal.Length, iris$Petal.Width), function(x) > (summary(aov(x~iris$Species > > > > On Tue, Oct 11, 2011 at 5:10 PM, Joshua Wong > wrote: >> Hi Guys, >> >> I have about 20 continous predictors and I want to do one-way anova to check >> the significance of each variable against the dependent variable. >> Apart from doing running the anova 20 times, is there a faster way? >> >> Thanks, >> Joshua >>[[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. >> > > > > -- > CH Chan > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Running R with browser without installing anything
Try Googling "R Portable" Ken Hutchison On Oct 20, 2554 BE, at 2:13 PM, jim holtman wrote: > It runs fine off a flash drive. > > On Thu, Oct 20, 2011 at 1:29 PM, Bogaso Christofer > wrote: >> Dear all, the company I work for has Matlab installed for >> statistical/mathematical calculations and really not ready to go with R >> (even installing exe file for R). Therefore I was wondering is it possible >> to do analysis R using browser like IE, without installing anything? >> >> >> >> Thanks for your suggestion. >> >> >> >> >> >> >>[[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > Jim Holtman > Data Munger Guru > > What is the problem that you are trying to solve? > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Arima Models - Error and jump error
Perhaps: require(forecast) ?auto.arima # Or look into package fitAR. The first performs seasonal optimization so it is likely better for your application. Ken Hutchison On Oct 21, 2554 BE, at 1:59 PM, Flávio Fagundes wrote: > Hi people, > > I´m trying to development a simple routine to run many Arima models result > from some parâmeters combination. > My data test have one year and daily level. > A part of routine is: > > for ( d in 0:1 ) > { for ( p in 0:3 ) > { for ( q in 0:3 ) > { for ( sd in 0:1 ) > { for ( sp in 0:3 ) > { for ( sq in 0:3 ) > { > Yfit=arima(Yst[,2],order=c(p,d,q),seasonal=list(order=c(sp,sd,sq),period=7),include.mean=TRUE,xreg=DU0) > }} > > Until the step 187 it´s run normally, but in the step 187 return a error and > stop the program. > >> > Yfit=arima(Yst[,2],order=c(1,0,1),seasonal=list(order=c(2,1,2),period=7),include.mean=TRUE,xreg=DU0) > > Error in optim(init[mask], armafn, method = "BFGS", hessian = TRUE, control > = optim.control, : > non-finite finite-difference value [1] > > My questions is: > > 1. What this error mean and why it occured? > 2. How can I do to this program disregard any error and to continue to run > until the end of looping? > 3. Someone know if already have any routine that do this? > > Thanks > Flávio > >[[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] glm-poisson fitting 400.000 records
Your memory shouldn't be capped there, try ?memory.size and ?memory.limit. Background less things. Good luck, Ken Hutchison On Oct 21, 2554 BE, at 11:57 AM, D_Tomas wrote: > My apologies for my vague comment. > > My data comprises 400.000 x 21 (17 explanatory variables, plus response > variable, plus two offsets). > > If I build the full model (only linear) I get: > > Error: cannot allocate vector of size 112.3 Mb > > I have a 4GB RAM laptop... Would i get any improvemnt on a 8GB computer > > Many thanks, > > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/glm-poisson-fitting-400-000-records-tp3925100p3925968.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.
Re: [R] Imputing Missing Data: A Good Starting Point?
Hope this helps: http://rss.acs.unt.edu/Rdoc/library/randomForest/html/rfImpute.html Ken Hutchison On Nov 1, 2554 BE, at 5:29 PM, Sascha Vieweg wrote: > Hello > > I am working on my first attempt to impute missing data of a data set with > systematically incomplete answers (school performance tests). I was googling > around for some information and found Amelia (Honaker et al., 2010) and the > mi package (Yu-Sung et al., n.d.). However, since I am new to this field, I > was wondering whether some experts could give a good recommendation of a > starting point for me, that is a point that combines theory as well as > practical examples. Of course, My primary interest is to complete the task in > time (1 week), however, I want to acquire skills for a program that provides > some future, and of course I want some background on what I am doing (and > what not). Could you help with some hints, experiences, and recommendations? > > Thank you. > > Regards > *S* > > -- > Sascha Vieweg, saschav...@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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 subset using variable
pansophy columbia.edu> writes: > > I am trying to create a loop that will perform a series of analyses. I am > using geeglm from geepack, which fails if there are any null values. > Creating a subset solves this, but do not seem to be able to set the subset > dynamically based on a changing variable. > > while (j <= y.num) { > > strSubset = as.character(df.IV$IV[j]) #Gives column name in quotes > df.data.sub = subset(df.data, strSubset>=0) > > #subset dataset is not created > > # analyses on subset take place > > j = j + 1 > } > > If I type the variable name in the formula it works, so I assume that I am > not creating the variable in a manner that allows it to be evaluated in the > subset function. Any help would be greatly appreciated! > > Michael > > -- > View this message in context: http://r.789695.n4.nabble.com/Create-subset-using-variable-tp4316812p4316812.html > Sent from the R help mailing list archive at Nabble.com. > > I think you want to try and use the double bracket with your df to access the column of interest in your data frame. To remove null values, you could use the na.omit() function, assuming when you say null values are represented as NAs: while (j <= y.num) { strSubset = as.character(df.IV$IV[j]) #Gives column name in quotes df.data.sub = df.data[[strSubset]] df.data.sub = na.omit(df.data.sub) # if null values are given as NA df.data.sub = df.data.sub[df.data.sub >= 0] # if null values are < 0 #subset dataset is not created # analyses on subset take place j = j + 1 } Hope that helps, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Placing a Shaded Box on a Plot
Stephanie Cooke gmail.com> writes: > > Hello, > > I would like to place shaded boxes on different areas of a > phylogenetic tree plot. Since I can not determine how to find axes on > the phylogenetic tree plot I am not able to place the box over certain > areas. Below is example code for the shaded box that I have tried to > use, and the first four values specify the position. > > rect(110, 400, 135, 450, col="grey", border="transparent") > > Any suggestions on how to place a shaded box to highlight certain > areas of a plot I would greatly appreciate. > > Stephanie, See ?polygon() or maybe ?segments(). I'm not familar with phylogenetic tree plots, so this might not work. You might have to play around with different values until you find the range of the axes. Good luck. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 cbind according to filename
Matthew Ouellette gmail.com> writes: > > Hi all, > > I'm just a beginner with R but I have not been able to search for any > relevant answer to my problem. I apologize if it has in fact been asked > before. > > Recently I've realized that I need to combine hundreds of pairs of data > frames. The filenames of the frames I need to combine have unique strings. > This is my best guess as to the approach to take: > > filenames<-list.files() > > filenames > [1] "a1.csv" "a2.csv" "b1.csv" "b2.csv" "c1.csv" "c2.csv" > > alldata<-lapply(filenames, read.csv, header=TRUE) > > names(alldata)<-filenames > summary(alldata) >Length Class Mode > a1.csv 27 data.frame list > a2.csv 27 data.frame list > b1.csv 27 data.frame list > b2.csv 27 data.frame list > c1.csv 27 data.frame list > c2.csv 27 data.frame list > > My next step would be to cbind files that share a common string at the > beginning, such as: > cbind(alldata[[1]],alldata[[2]]) > cbind(alldata[[3]],alldata[[4]]) > cbind(alldata[[5]],alldata[[6]]) > ... > > but file list is hundreds of files long (but is sorted alphanumerically > such as in this example - not sure if this is relevant). If I had to > guess, I'd do something like this: > > which(names(alldata)==...), to identify which elements to combine based on > unique filename > > OR > x<-seq(1,length(alldata), 2) > y=x+1 > z<-cbind(x,y) > z > x y > [1,] 1 2 > [2,] 3 4 > [3,] 5 6 > > to use the frame created in z to combine based on rows, > > then use a looped cbind function (or *apply function with nested cbind > function?) using the previously returned indexes to create my new combined > data frames, including a step to write the frames to a new unique filename > (not sure how to do that step in this context). These last steps I've > tried a lot of code but nothing worth mentioning as it has all failed > miserably. > > I appreciate the help, > > M > > [[alternative HTML version deleted]] > > Hi Matthew, You could try using substr() if the cbind is based on a common string in the file name just makes sure that the strings in filenames is in the same order as the files are in list.files: a1 <- data.frame("col1" = seq(1,10, 1)) a2 <- data.frame("col2" = seq(11,20, 1)) b1 <- data.frame("col3" = seq(21,30, 1)) b2 <- data.frame("col4" = seq(31,40, 1)) filenames <- c("a1", "a2", "b1", "b2") list.files <- list(a1, a2, b1, b2) first.letter <- substr(filenames, 1,1) unique.first.letter <- unique(first.letter) l.files <- list() for(i in 1:length(unique.first.letter)){ l.files[[i]] = as.data.frame(list.files[first.letter == unique.first.letter[i]]) } HTH, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 cbind according to filename
Matthew Ouellette gmail.com> writes: > > Hi all, > > I'm just a beginner with R but I have not been able to search for any > relevant answer to my problem. I apologize if it has in fact been asked > before. > > Recently I've realized that I need to combine hundreds of pairs of data > frames. The filenames of the frames I need to combine have unique strings. > This is my best guess as to the approach to take: > > filenames<-list.files() > > filenames > [1] "a1.csv" "a2.csv" "b1.csv" "b2.csv" "c1.csv" "c2.csv" > > alldata<-lapply(filenames, read.csv, header=TRUE) > > names(alldata)<-filenames > summary(alldata) >Length Class Mode > a1.csv 27 data.frame list > a2.csv 27 data.frame list > b1.csv 27 data.frame list > b2.csv 27 data.frame list > c1.csv 27 data.frame list > c2.csv 27 data.frame list > > My next step would be to cbind files that share a common string at the > beginning, such as: > cbind(alldata[[1]],alldata[[2]]) > cbind(alldata[[3]],alldata[[4]]) > cbind(alldata[[5]],alldata[[6]]) > ... > > but file list is hundreds of files long (but is sorted alphanumerically > such as in this example - not sure if this is relevant). If I had to > guess, I'd do something like this: > > which(names(alldata)==...), to identify which elements to combine based on > unique filename > > OR > x<-seq(1,length(alldata), 2) > y=x+1 > z<-cbind(x,y) > z > x y > [1,] 1 2 > [2,] 3 4 > [3,] 5 6 > > to use the frame created in z to combine based on rows, > > then use a looped cbind function (or *apply function with nested cbind > function?) using the previously returned indexes to create my new combined > data frames, including a step to write the frames to a new unique filename > (not sure how to do that step in this context). These last steps I've > tried a lot of code but nothing worth mentioning as it has all failed > miserably. > > I appreciate the help, > > M > > [[alternative HTML version deleted]] > > Hi Matthew, You could try using substr() if the cbind is based on a common string in the file name just makes sure that the strings in filenames is in the same order as the files are in list.files: a1 <- data.frame("col1" = seq(1,10, 1)) a2 <- data.frame("col2" = seq(11,20, 1)) b1 <- data.frame("col3" = seq(21,30, 1)) b2 <- data.frame("col4" = seq(31,40, 1)) filenames <- c("a1", "a2", "b1", "b2") list.files <- list(a1, a2, b1, b2) first.letter <- substr(filenames, 1,1) unique.first.letter <- unique(first.letter) l.files <- list() for(i in 1:length(unique.first.letter)){ l.files[[i]] = as.data.frame(list.files[first.letter == unique.first.letter[i]]) } HTH, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] data.table cant find function melt?
Hi all, trying to use the melt function in data.table and I'm getting an error Anyone seen this before or know how to fix it? Thanks str(Distdata) Classes ‘data.table’ and 'data.frame': 828451 obs. of 3 variables: $ Poly1 : int 50088 50088 50088 50088 50088 50088 50088 50088 50088 50088 ... $ Poly2 : int 44884 11542 11543 11540 11541 11546 11547 11544 11545 11548 ... $ Distance: int 788641 3794345 3652511 3915074 3895469 3639175 3644151 3648356 3646023 3615863 ... - attr(*, ".internal.selfref")= melt.data.table(Distdata, id.vars=Poly1, measure.vars=Poly2) Error: could not find function "melt.data.table" melt(Distdata, id.vars=Poly1, measure.vars=Poly2) Error: could not find function "melt"] __ 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] Are melt and dcast with ffdf possible?
Having trouble getting melt and dcast to work with ffdf I'm trying to cast 3 columns to a square matrix With a regular data.frame. comb <- expand.grid((1:10),(1:10)) dim(comb) comb$Dist <- (1:100) c.melt <- melt(comb, id.vars=c("Var1","Var2")) dcast(c.melt,Var2~Var1) goes from > comb Var1 Var2 Dist 1 111 2 212 3 313 4 414 5 515 6 616 . to > c.melt Var1 Var2 variable value 1 11 Dist 1 2 21 Dist 2 3 31 Dist 3 4 41 Dist 4 5 51 Dist 5 6 61 Dist 6 . to > dcast(c.melt,Var1~Var2) Var1 1 2 3 4 5 6 7 8 9 10 1 1 1 11 21 31 41 51 61 71 81 91 2 2 2 12 22 32 42 52 62 72 82 92 3 3 3 13 23 33 43 53 63 73 83 93 4 4 4 14 24 34 44 54 64 74 84 94 5 5 5 15 25 35 45 55 65 75 85 95 6 6 6 16 26 36 46 56 66 76 86 96 7 7 7 17 27 37 47 57 67 77 87 97 8 8 8 18 28 38 48 58 68 78 88 98 9 9 9 19 29 39 49 59 69 79 89 99 10 10 10 20 30 40 50 60 70 80 90 100 no trouble. With ffdf it breaks on the melt step comb.ff <- expand.ffgrid(ff(1:10),ff(1:10)) dim(comb.ff) comb.ff$Dist <- ff(1:100) > comb.ff ffdf (all open) dim=c(100,3), dimorder=c(1,2) row.names=NULL ffdf virtual mapping PhysicalName VirtualVmode PhysicalVmode AsIs VirtualIsMatrix PhysicalIsMatrix PhysicalElementNo PhysicalFirstCol PhysicalLastCol PhysicalIsOpen Var1 Var1 integer integer FALSE FALSEFALSE 11 1 TRUE Var2 Var2 integer integer FALSE FALSEFALSE 21 1 TRUE Dist Dist integer integer FALSE FALSEFALSE 31 1 TRUE ffdf data Var1 Var2 Dist 1 111 2 212 3 313 4 414 5 515 6 616 c.melt.ff <- melt(comb.ff, id.vars=c("Var1","Var2")) > c.melt.ff value NA NA 1 1 1 1 2 2 1 2 3 3 1 3 4 4 1 4 5 5 1 5 6 6 1 6 7 7 1 7 . Is it possible to use this method with ffdf? I appreciate any help Ken __ 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 with ff matrix indexing and value assignment
Hi all I'm trying to make some assignments to an ffdf using values coming in as 3 columns (row, col, values) As an example with a regular matrix assigning data (d) to row r and column c from a data frame assigns the 3 specific values as desired reg.mat <- matrix(0, nrow=5, ncol=5) > reg.mat [,1] [,2] [,3] [,4] [,5] [1,]00000 [2,]00000 [3,]00000 [4,]00000 [5,]00000 coldat <- data.frame(r = c(1,2,4), c = c(2,1,3), d=c(10,11,12)) > coldat r c d 1 1 2 10 2 2 1 11 3 4 3 12 reg.mat[cbind(coldat$r, coldat$c)] <- coldat$d > reg.mat [,1] [,2] [,3] [,4] [,5] [1,]0 10000 [2,] 110000 [3,]00000 [4,]00 1200 [5,]00000 However using an ff matrix with an incoming 3 column ffdf I cant seem to get it to go... ff.mat<-ff(as.integer(0), dim=c(5,5)) > tst.mat ff (open) integer length=25 (25) dim=c(5,5) dimorder=c(1,2) [,1] [,2] [,3] [,4] [,5] [1,]00000 [2,]00000 [3,]00000 [4,]00000 [5,]00000 coldatff <- ffdf(r=ff(as.integer(c(1,2,4))),c=ff(as.integer(c(2,1,3))),d=ff(as.integer(c(10,11,12 > coldatff ffdf (all open) dim=c(3,3), dimorder=c(1,2) row.names=NULL ffdf virtual mapping PhysicalName VirtualVmode PhysicalVmode AsIs VirtualIsMatrix PhysicalIsMatrix PhysicalElementNo PhysicalFirstCol PhysicalLastCol rr integer integer FALSE FALSEFALSE 11 1 cc integer integer FALSE FALSEFALSE 21 1 dd integer integer FALSE FALSEFALSE 31 1 PhysicalIsOpen r TRUE c TRUE d TRUE ffdf data r c d 1 1 2 10 2 2 1 11 3 4 3 12 ff.mat[cbind(coldatff$r,coldatff$c)] <-coldatff$d > ff.mat ff (open) integer length=25 (25) dim=c(5,5) dimorder=c(1,2) [,1] [,2] [,3] [,4] [,5] [1,]00000 [2,]00000 [3,]00000 [4,]00000 [5,]00000 Using cbind = still getting only zeros. Tried a few other methods I just cant seem to wrap my head around how to do this. I had a look at ffindexset, but that looks like assigning whole rows at a time. I appreciate any help !! Thanks Ken __ 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] Opposite color in R
peter dalgaard gmail.com> writes: > > > > On 25 Jul 2015, at 21:49 , Atte Tenkanen utu.fi> wrote: > > > > Hi, > > > > I have tried to find a way to find opposite or complementary colors in R. > > > > I would like to form a color circle with R like this one: http://nobetty.net/dandls/ colorwheel/complementary_colors.jpg > > > > If you just make a basic color wheel in R, the colors do not form complementary color circle: > > > > palette(rainbow(24)) > > Colors=palette() > > pie(rep(1, 24), col = Colors) > > > > There is a package ”colortools” where you can find function opposite(), but it doesn’t work as is > said. I tried > > > > library(colortools) > > opposite("violet") and got green instead of yellow and > > > > opposite("blue") and got yellow instead of orange. > > > > Do you know any solutions? > > Not directly, but a few hints: > > First read up on "complementary colors" in Wikipedia. In particular, note that the traditional color > circle does not satisfy the modern definition of opposite-ness. E.g. red paint mixed with green paint is > brown, not black or grey. > > The construction of the color circle is simple in principle: red, blue, yellow go at 0, 120, 240 degrees, the > other colors on the circle are formed by mixing two primaries in varying proportions: green (at 180 deg) is > an equal mixture of blue and yellow, violet (at 60 deg) of blue and red, orange (at 300 deg) of red and yellow. > Blue-green (at 150 deg) would be half blue, half green, alias three quarter blue, one quarter yellow. Etc. > > The tricky bit is that the above mixtures are subtractive mixtures (mixing paint rather than light beams) > and I don't know how to make a subtractive color mixture in the additive RGB space that we usually work in. > Maybe there are tools in the colortools package? > > -pd > > > > > Atte Tenkanen To start with, you should be specifying your "colors" or lights actually in an additive color space like CIE 1931 xy, https://en.wikipedia.org/wiki/CIE_1931_color_space which you can do in the colorspace package. But this is based on an average observer and the results are unlikely to match a given individual's vision. On top of that, decisions made when this norm was specified are such that it deviates from human vision for short wavelengths so that you would be better off using a corrected version like that proposed by Judd in the 1950's or for the most recent suggestion see ww.cvrl.org under New CIE XYZ functions transformed from the CIE (2006) LMS functions best, Ken -- Kenneth Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ 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] Help with GLM starting values in user defined link function
csiro.au> writes: > I'm trying to fit a binomial GLM with user defined link function (negative exponential), however I seem to > be unable to find the correct starting values to initialise such a model. I've tried taking starting > values from a logistic and log models fit to the same data and also tried to substitute the intercept from > the null model in as the starting value for this model, however all continue to return the same error. > > Andrew > > ## Example fit of negative exponential binomial GLM > > ## define link function > negexp <- function() > { > linkfun <- function(mu) 1-exp(-mu) > linkinv <- function(eta) -log(1-eta) > mu.eta <- function(eta) 1/(1-eta) > valideta <- function(eta) TRUE > link <- paste0("negexp") > structure(list(linkfun = linkfun, linkinv = linkinv, >mu.eta = mu.eta, valideta = valideta, name = link), > class = "link-glm") > } > ---SNIP--- Take a look at the limits of eta for the extreme values of mu and compare them with the linear predictor of your link applied to say the fitted values of your logit fit. It seems to suggest that two values fall outside the range of valid eta, according to your linkfun: c(62, 83). I got it to work with these removed although there were lots of other warnings that you might have to worry about. Also, when choosing start values you might want to base them on a fit with your link rather than a different one. So, I got start values by trying EV <- negexp()$linkfun(fitted(fit.logit)) LE.lm <- lm(EV ~ eco + geog, testDat) Ec <- coef(LE.lm) with these defined as in your mail (sorry I snipped your code out). So, I found which(fitted(LE.lm) > (1 - exp(-1))) 62 83 62 83 and then glm(y ~ eco + geog, family = binomial(negexp()), data = testDat[-c(62, 83), ], start = Ec) Coefficients: (Intercept) eco geog 1.593e-012.085e-014.713e-06 Degrees of Freedom: 97 Total (i.e. Null); 95 Residual Null Deviance: 134.4 Residual Deviance: 112.3AIC: 118.3 There were 27 warnings (use warnings() to see them) HTH > > Andrew Hoskins > Postdoctoral reasearch fellow > Ecosystem Sciences > CSIRO > > E Andrew.Hoskins csiro.au T +61 2 6246 5902 > Black Mountain Laboratories > Clunies Ross Street, Acton, ACT 2601, Australia > www.csiro.au > > -- Kenneth Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 matrix multiplication slowdown
Hi all. A question about performance of matrix multiplication. I have two relatively large matrices: A is 100x3072, all integers 0-255, not sparse B is 1016x3072, all integers 0-255, not sparse The command z<-B %*% t(A) works fine and takes roughly 0.2 seconds . If I add one row to B, the same command takes 2.4 seconds; at 1050 rows in B, the command is up to almost 4 seconds. Just trying to understand why the big slowdown is occurring, especially since the matrices I actually want to multiply have 1000 and 5000 rows, not 100 and 1017. Thanks, Ken (Macbook Pro running 10.11.6, 16Gb, R v 3.3.1) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R matrix multiplication slowdown
I've done more searching and found a problem with the data in one of the matrices that was corrupting the calculation. Data now fixed and problem is solved. Apologies if anyone wasted time on this. Ken On Fri, Jan 27, 2017 at 8:29 AM, Jeff Newmiller wrote: > You are asked by the Posting Guide to provide a reproducible example and > to post in plain text (because HTML gets mangled). I would guess your > problem has nothing to do with multiplication, but without the code there > is no way to say for sure. > -- > Sent from my phone. Please excuse my brevity. > > On January 26, 2017 2:21:07 PM PST, ken eagle > wrote: > >Hi all. A question about performance of matrix multiplication. > > > > > > > >I have two relatively large matrices: > > > > > > > >A is 100x3072, all integers 0-255, not sparse > > > >B is 1016x3072, all integers 0-255, not sparse > > > > > > > >The command z<-B %*% t(A) works fine and takes roughly 0.2 seconds . > >If I > >add one row to B, the same command takes 2.4 seconds; at 1050 rows in > >B, > >the command is up to almost 4 seconds. Just trying to understand why > >the > >big slowdown is occurring, especially since the matrices I actually > >want to > >multiply have 1000 and 5000 rows, not 100 and 1017. > > > > > > > >Thanks, > > > >Ken > > > > > > > >(Macbook Pro running 10.11.6, 16Gb, R v 3.3.1) > > > > [[alternative HTML version deleted]] > > > >__ > >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >https://stat.ethz.ch/mailman/listinfo/r-help > >PLEASE do read the posting guide > >http://www.R-project.org/posting-guide.html > >and provide commented, minimal, self-contained, reproducible code. > [[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] History pruning
Hi, I find that a typical workflow for me looks something like this: 1) import some data from files 2) mess around with the data for a while 3) mess around with plotting for a while 4) get a plot or analysis that looks good 5) go back through my history to make a list of the shortest command sequence to recreate the plot or analysis 6) send out that sequence to colleagues, along with the generated plots or analysis output I wonder if there are any tools people have developed to help with step 5. Typically I do something like this: 5a) save my entire history to a text file 5b) open it up in Emacs 5c) prune any lines that don't have assignment operators 5d) prune any plotting commands that were superseded by later plots and then start on other more subtle stuff like pruning assignments that were later overwritten, unless the later assignments have variable overlap between the LHS and the RHS. Then I just start eyeballing it. Would any deeper introspection of the history expressions be feasible, e.g. detecting statements that have no side effects, dead ends, etc. The holy grail would be something like "show me all the statements that contributed to the current plot" or the like. Thanks. -- Ken Williams Research Scientist The Thomson Reuters Corporation Eagan, MN __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] History pruning
On 7/30/08 1:59 PM, "Marc Schwartz" <[EMAIL PROTECTED]> wrote: > I (and many others) use ESS (Emacs Speaks Statistics), in which case, I > have an R source buffer in the upper frame and an R session in the lower > frame. I also use ESS to edit my R code (inside Aquamacs Emacs), but I usually use the OS X port R.app for most of my interactive sessions. Together I think those give me roughly the same amount of IDE-like support as you've got in your setup. I think the ess-smart-underscore command alone is worth the price of admission. But none of that directly addresses the issue of automatically (or semi-automatically) taking a long sequence of commands and pruning it down to a smaller sequence that produces the same results. Theoretically the allowable prunings would be akin to those of a good optimizer. And the R language would seem fairly amenable to such things, with its pass-by-value functional semantics, etc. -- Ken Williams Research Scientist The Thomson Reuters Corporation Eagan, MN __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] History pruning
On 7/31/08 11:01 AM, "hadley wickham" <[EMAIL PROTECTED]> wrote: > I think that would be a very hard task - Well, at least medium-hard. But I think significant automatic steps could be made, and then a human can take over for the last few steps. That's why I was enquiring about "tools" rather than a complete solution. Does R provide facilities for introspection or interrogation of expression objects? I couldn't find anything useful on first look: > methods(class="expression") no methods were found > dput(expression(foo <- 5 * bar)) expression(foo <- 5 * bar) > str(expression(foo <- 5 * bar)) expression(foo <- 5 * bar) > it's equivalent to taking a > long rambling conversation and then automatically turning it into a > concise summary of what was said. I think you must have human > intervention. It's not really equivalent, natural language has ambiguities and subtleties that computer languages, especially functional languages, intentionally don't have. By their nature, computer languages can be turned into parse trees unambiguously and then those trees can be manipulated. But coincidentally I work in a Natural Language Processing group, and one of the things we do is create exactly the kind of concise summaries you describe. =) -- Ken Williams Research Scientist The Thomson Reuters Corporation Eagan, MN __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] History pruning
On 7/31/08 2:12 PM, "Duncan Murdoch" <[EMAIL PROTECTED]> wrote: > > expression() returns a list of language objects, and we only asked for > one. We can look inside it: Hey, cool. Now let me see if I can do anything useful with that. Thanks. -Ken -- Ken Williams Research Scientist The Thomson Reuters Corporation Eagan, MN __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] History pruning
On 8/1/08 12:40 PM, "Richard M. Heiberger" <[EMAIL PROTECTED]> wrote: > >> 5a) save my entire history to a text file >> 5b) open it up in Emacs >> 5c) prune any lines that don't have assignment operators > > No one has yet mentioned the obvious. ESS does your 5a 5b 5c with >M-x ess-transcript-clean-buffer I think you mean just 5a & 5b, right? Lines with syntax errors are (I think) removed, but that's it. That part is relatively easy to perform as the first step of a tool, just by running commands through R's parse() and discarding anything that throws an exception. > On automatic content analysis, that is tougher. I would be scared to do your >> 5d) prune any plotting commands that were superseded by later plots True. There are lots of (perhaps relatively common) edge cases that would have to be taken into account. Perhaps a more interactive approach would be better, something like "get rid of this plot command and all subsequent modifications to its canvas". Not sure. My basic philosophy on stuff like this is, given the choice of me fumbling around using tools and me fumbling around without using tools, I tend to do better when I have tools. > You also have to trust that there are no side effects, which I wouldn't > want to do, because plot() changes the value of par() parameters. It does? I wasn't aware of that, could you give an example? -- Ken Williams Research Scientist The Thomson Reuters Corporation Eagan, MN __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 R console for OS X?
Anh Tran ucla.edu> writes: > I always open more than 1 R console in Windows. I can't figure out a way to > do this with OS X yet. I need that to utilize the duo core on my desktop. > How would I do that? > Have a look here https://stat.ethz.ch/pipermail/r-sig-mac/2008-April/004814.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] History pruning
On 8/1/08 1:13 PM, "Richard M. Heiberger" <[EMAIL PROTECTED]> wrote: > I meant 5a 5b 5c. Multiple-line commands are handled correctly. > What is is doing is looking for "> " and " +" prompts. Anything else > is removed. When I said "5c) prune any lines that don't have assignment operators" I meant to take a sequence like this (to pick a semi-random chunk from my history log): --- df <- data.frame(x=2:9, y=(1:8)^2) cor(df) ?cor mad(c(1:9)) ?reshape a <- matrix(1:12, nrow=3) b <- matrix(2:13, nrow=3) b <- matrix(4:15, nrow=3) b <- matrix(2:13, nrow=3) c <- matrix(4:15, nrow=3) a b c --- And turn it into this: --- df <- data.frame(x=2:9, y=(1:8)^2) a <- matrix(1:12, nrow=3) b <- matrix(2:13, nrow=3) b <- matrix(4:15, nrow=3) b <- matrix(2:13, nrow=3) c <- matrix(4:15, nrow=3) --- Obviously I wouldn't *always* want this performed, but selectively it would be quite nice. Further, if the dependency graph among variable definitions were computable, the sequence could be reduced to this: --- df <- data.frame(x=2:9, y=(1:8)^2) a <- matrix(1:12, nrow=3) b <- matrix(2:13, nrow=3) c <- matrix(4:15, nrow=3) --- Note that the starting point of all of this is a sequence of commands (the output of savehistory(), so separating commands from output isn't necessary. I've made a bit of progress on this, hopefully I can get clearance to show my work soon. It would be nice if this could be hooked into ESS for selective pruning or something. -Ken -- Ken Williams Research Scientist The Thomson Reuters Corporation Eagan, MN __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] History pruning
On 8/8/08 1:04 PM, "Greg Snow" <[EMAIL PROTECTED]> wrote: > Ken, > > Others have given hints on pruning the history, but are you committed to doing > this way? Not necessarily. Only the starting point & ending point really matter; I'd like to be able to start with a transcript of a bunch of aimless commands (e.g. the output of sink() or of ess-transcript-clean-buffer or a history transcript), and end up with a nice focused handful of commands suitable for showing to other people. I'm sure the final goal can't typically be achieved fully automatically, but some kind of support from tools would be great. Thanks for mentioning plot2script() and the TeachingDemos package, those are indeed nice examples to look at. -- Ken Williams Research Scientist The Thomson Reuters Corporation Eagan, MN __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] new package MLCM: Maximum Likelihood Conjoint Measurement
This is to announce a new package MLCM on CRAN. The package provides functions for estimating perceptual scales by maximum likelihood from data collected in a conjoint measurement experiment. Data for conjoint measurement are typically collected using a psychophysical procedure. The stimuli vary along 2 or more dimensions. The observer views pairs of stimuli and judges which stimulus of each pair is higher on a specified dimension. For example, stimuli may be goods baskets containing amounts of milk and honey (dimensions) and the subject may order each pair of baskets by subjective desirability. This package contains tools to estimate the additive contribution of the n scales to the judgment by a maximum likelihood method under several hypotheses of how the perceptual dimensions interact. -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 convert numbers to words?
Derek Norton gmail.com> writes: > I am trying to convert numbers to English words, e.g. 123 -> One > hundred twenty three. After some searching, I have been unable to > find any info on this. I could certainly write code to do it, but my > question is this: Does anyone know of a function that does this? > > Thanks, > Derek McCrae Norton Try Rnews Volume 5/1, May 2005, The Programmer's Niche by John Fox How Do You Spell That Number? -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave, lty = 3 line incorect in pdf output
Hi Achim, Thanks for trying. Maybe, it's a Mac-thing. I'll wait to see if I get other replies. It's strange, as the quartz graphic is correct but the pdf produced by Sweave doesn't contain the dotted line, with the caveat, on my Mac for the moment. Ken Quoting Achim Zeileis : Ken, I can't contribute much, just that I tried to look into it and can't replicate it. I tried it both with .Stex and .Rnw yielding identical results, just like plotting it interactively (on my default X11) and printing it via dev.copy2pdf(). All of the approaches seemed to yield the same output which looks ok. Just for the record... Z R> sessionInfo() R version 2.10.1 (2009-12-14) i486-pc-linux-gnu locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] fortunes_1.3-7 On Thu, 11 Feb 2010, Ken Knoblauch wrote: I'm having a problem with dotted lines (lty = 3) in the pdf output in documents generated with Sweave. In the displayed pdf, the dotted line does not show up and in the printed output, it is there but does not seem to respect the lwd argument, for example, it is very faint despite using lwd = 3. The dotted line is correct in a quartz window and if I save the Quartz window to a pdf and include it in the tex document, then the dotted line is there at the correct line width. Here is a short example, using the Stex convention for Sweave. I saved the quartz window in a file called quartzSave.pdf after running the document through Sweave a first time without the \includegraphics{quartzSave} line. \documentclass[10pt]{article} \usepackage{graphicx} \begin{document} Test of lty = 3 argument. \begin{Scode}{fig=TRUE,eps=FALSE} x <- 1:10 plot(x, type = "l", lty = 3, lwd = 3) lines(x, 0.5 * x, type = "l") \end{Scode} Saved from Quartz window: \includegraphics{quartzSave} \end{document} I have attached the pdf created by Sweave (which is missing the dotted lines) in case it can get through the filter to R-help. sessionInfo() R version 2.10.1 Patched (2010-02-01 r51089) i386-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods [7] base loaded via a namespace (and not attached): [1] tools_2.10.1 Thanks for any help. Ken -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html ---- -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave, lty = 3 line incorect in pdf output
Some follow-up after Achim's message, If I open the Sweave created pdf, lty3Test-001.pdf, attached to the first mail, with the display command from imageMagick, indeed, the dotted line is present, but faintly, as with the hardcopy printout, i.e., not respecting the lwd = 3 argument. But, the dotted line is absent if viewed with Mac's Preview.app and the pdf viewer of TeXShop. I don't have acrobat on my Mac to test that, but it seems to in part, at least, viewer related. Still, it would be good to track this down and ideally solve it. Thanks. Ken Quoting Achim Zeileis : Ken, I can't contribute much, just that I tried to look into it and can't replicate it. I tried it both with .Stex and .Rnw yielding identical results, just like plotting it interactively (on my default X11) and printing it via dev.copy2pdf(). All of the approaches seemed to yield the same output which looks ok. Just for the record... Z R> sessionInfo() R version 2.10.1 (2009-12-14) i486-pc-linux-gnu locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] fortunes_1.3-7 On Thu, 11 Feb 2010, Ken Knoblauch wrote: I'm having a problem with dotted lines (lty = 3) in the pdf output in documents generated with Sweave. In the displayed pdf, the dotted line does not show up and in the printed output, it is there but does not seem to respect the lwd argument, for example, it is very faint despite using lwd = 3. The dotted line is correct in a quartz window and if I save the Quartz window to a pdf and include it in the tex document, then the dotted line is there at the correct line width. Here is a short example, using the Stex convention for Sweave. I saved the quartz window in a file called quartzSave.pdf after running the document through Sweave a first time without the \includegraphics{quartzSave} line. \documentclass[10pt]{article} \usepackage{graphicx} \begin{document} Test of lty = 3 argument. \begin{Scode}{fig=TRUE,eps=FALSE} x <- 1:10 plot(x, type = "l", lty = 3, lwd = 3) lines(x, 0.5 * x, type = "l") \end{Scode} Saved from Quartz window: \includegraphics{quartzSave} \end{document} I have attached the pdf created by Sweave (which is missing the dotted lines) in case it can get through the filter to R-help. sessionInfo() R version 2.10.1 Patched (2010-02-01 r51089) i386-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods [7] base loaded via a namespace (and not attached): [1] tools_2.10.1 Thanks for any help. Ken -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html -------- -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] NextMethod() example from S Programming by Vena bles and Ripley (page 78)
blue sky gmail.com> writes: > S Programming by Venables and Ripley (page 78) has the example listed > at the end of this email. However, I get the following error when I > try the example. I don't understand the descriptions of NextMethod on > its help page. Could somebody let me know how to fix the error of this > example? > > test(x) > c1 > c2 > Error in NextMethod() : no method to invoke > Calls: test -> test.c1 -> NextMethod -> test.c2 -> NextMethod > Execution halted > > > test=function(x) UseMethod('test') > > test.c1=function(x) { > cat('c1\n') > NextMethod() > x > } > > test.c2=function(x) { > cat('c2\n') > NextMethod() > x > } > > test.c3=function(x) { > cat('c3\n') > x > } > > x=1 > class(x)=c('c1','c2') > test(x) It works fine for me if you add a default method, which I think is what it is looking for. test.default <- function(x){ cat("default") x } test(x) c1 c2 default[1] 1 attr(,"class") [1] "c1" "c2" -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] lty dots pdf issue
Roger Koenker uiuc.edu> writes: > I'm trying to redo an old plot with: > > sessionInfo() > R version 2.11.0 Under development (unstable) (2010-02-09 r51113) > x86_64-apple-darwin9.8.0 > When I do: > > pdf("lty.pdf",height = 6, width = 8) > u <- 1:100/100 > y <- matrix(rep(1:10,each = 100),100) > matplot(u,y,lwd = 2,type ="l") > dev.off() > > the line types that have dots are difficult to distinguish because the "dots" > that should appear are rendered as very thin vertical l ines and it appears > that the dashes are rendered without the lend "round" feature even though > par() reports that that is the setting. I'm viewing all this with Acrobat 9 pro, > but my printer produces something quite consistent with what is viewable > on the screen. Hi, Could this be related to the problem that was driving me crazy last week https://www.stat.math.ethz.ch/pipermail/r-sig-mac/2010-February/007123.html but resolved in the latest patched version? HTH, Ken > Apologies in advance if this has an obvious resolution, I didn't see anything > in the r-help archive. > > Roger > > url:www.econ.uiuc.edu/~rogerRoger Koenker > emailrkoenker uiuc.eduDepartment of Economics > vox: 217-333-4558University of Illinois > fax: 217-244-6678Urbana, IL 61801 > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Direction and scaling of cumulative distribution in ecdfplot
Jeff Stevens googlemail.com> writes: > I have two questions regarding the ecdfplot function in the > latticeExtra package. > 1. How can I plot the fraction of values >= x rather than <=x, like > the what = "1-F" argument in the Ecdf function in the Hmisc package? > > 2. When I try to log-transform the y-axis, I get a warning that it > can't have log Y-scale, and it fails to scale properly: > How can I log-transform the y-axis in ecdfplot? Here is a test > example of my analysis in R version 2.10.1 in Ubuntu 9.10: > > resp <- c(0.23, 0.09, 0.05, 0.02, 0.38, 1, 0.04, 0.01, 0.17, 0.04, 0.01, 0.17, 0.5) > > id <- c(rep(1, 5), rep(2, 4), rep(3, 4)) > > testdata <- data.frame(id, resp) > > ecdfplot(~resp | id, data = testdata, scales = list(x = list(relation = "free", log = TRUE),y = list(log = > TRUE)), type = "p") > Warning message: > In densityplot.formula(x = ~resp | id, data = list(id = c(1, 1, : > Can't have log Y-scale If I understand what you are trying to do, I put this together a while back (which was not optimal but it worked at the time), but I haven't tested it since. ecdflt <- function(x) { cdf <- as.vector( sapply(sort(x, decreasing = TRUE), function(y) sum(x >= y)/length(x)) ) cbind(sort(x, decreasing = TRUE), cdf) } panel.ecdflt <- function(x, logY = TRUE, ...) { xy <- ecdflt(x) if (logY) xy[, 2] <- log10(xy[, 2]) panel.xyplot(xy[, 1], xy[, 2], ...) } xyplot(X ~ X | F, panel = function(x, y = NULL, ...){ panel.ecdflt(x, ...) }) > > Many thanks, > Jeff > > -- > Jeff Stevens > Research Scientist > Center for Adaptive Behavior and Cognition > Max Planck Institute for Human Development > Lentzealle 94 > 14195 Berlin, Germany > -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Question regarding package submission to CRAN
Gates, Michael unt.edu> writes: > Members, > I recently submitted my first package to the submissions ftp site on CRAN (7.3.09). The package has > remained on the server since with no action? Do package review/updates occur monthly? When I submitted, I > sent an email to CRAN to let them know about the package and the license under which the package operates. > Since this is my first time, I am just trying to understand the process. > > Any elaboration about how long the process takes or whether I failed to meet the submission process, etc. > would be helpful. I have referenced the package in one published article and in another article to be > published later this year. I would like to direct people to CRAN but now I am not sure how long the process is > or whether my package will be accepted for posting to the CRAN mirrors. Could be that the responsible person is on vacation... -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] xtable formatting: RED for negative numbers?
I've been experimenting recently with the fantastic Sweave/xtable combination for generating latex. In the xtable vignette, I found this great example of printing a ts object by months. Is there a way to modify this code to generate RED numbers inside xtable for negative results in x.ts? Thanks in advance. - Ken # Sweave/xtable snippet below -- \begin{table}[ht] <>= x.ts <- ts(rnorm(100), start = c(1954, 7), frequency = 12) x.table <- xtable( x.ts, digits = 1 ) print( x.table, floating = FALSE ) @ \end{table} -- View this message in context: http://www.nabble.com/xtable-formatting%3A-RED-for-negative-numbers--tp24712208p24712208.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] Compare lm() to glm(family=poisson)
Mark Na gmail.com> writes: > > Dear R-helpers, > I would like to compare the fit of two models, one of which I fit using lm() > and the other using glm(family=poisson). The latter doesn't provide > r-squared, so I wonder how to go about comparing these > models (they have the same formula). > > Thanks very much, > > Mark Na > I'm not sure what you are trying to do but it might be informative to compare the diagnostic plots from the fits. Remember that Poisson distributed data is heteroscedastic, mean = variance, which isn't the default hypothesis when fitting with lm. Also, the default link function with the poisson family is log. So, these are things to take into account in any potential comparison. Ken -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Stack with factors
Kenneth Roy Cabrera Torres une.net.co> writes: > Hi R users: > I found that I cannot stack() a data.frame with factors. > db1<-data.frame(replicate(6,factor(sample(c("A","B"),6,replace=TRUE > str(db1) > db2<-stack(db1) > db2 > "db2" does not have any row. > How can I stack them by the variables X1,X2,...,X6? you can see what is happening in stack.data.frame you have a line x <- x[, unlist(lapply(x, is.vector)), drop = FALSE] and lapply(x, is.vector)) is applied to each column of the data frame but you can verify for yourself that a factor yields FALSE here x <- db1[[1]] is.vector(x) [1] FALSE so I think that this at least explains why it doesn't work as you expected. > Thank you for your help. > > Kenneth -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Excel date to R format
One useful package is "chron": example: library(chron) #convert excel time to date time format etime = 39965.0004549653 orig =chron("12/30/1899"); # "origin" of excel time. date.time = orig + etime; substr(as.character(date.time), 2, 18) # as character without parentheses. HTH, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] xtable - how to add a "sum of values in a row" column?
Hi, I saw this example for 2.10 Time series in the xtable gallery documentation. http://cran.r-project.org/web/packages/xtable/vignettes/xtableGallery.pdf How would I add a column at the end "Total" which sums the row, with minimal changes to the code below? Thanks in advance. - Ken 2.10 Time series > temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)), start = c(1954, + 7), frequency = 12) > temp.table <- xtable(temp.ts, digits = 0) > caption(temp.table) <- "Time series example" > print(temp.table, floating = FALSE) Time series example Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 1954 2 3 6 8 11 10 1955 11 13 15 16 16 18 20 22 21 22 24 24 1956 25 26 28 28 28 28 29 31 31 32 33 34 1957 35 36 38 39 39 41 42 42 41 42 43 45 1958 46 46 47 47 49 51 54 56 58 59 61 61 1959 62 61 62 62 62 63 62 64 64 66 67 68 1960 67 67 69 71 74 75 77 78 79 80 82 81 1961 84 86 87 88 89 91 94 94 94 94 96 97 1962 98 99 101 102 104 105 108 107 106 107 -- View this message in context: http://www.nabble.com/xtable---how-to-add-a-%22sum-of-values-in-a-row%22-column--tp25635552p25635552.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] xtable - how to add a "sum of values in a row" column?
I wonder if the right approach is to convert temp.ts into a matrix, add the column at the end, and then call xtable()... ...anyone have any suggestions? TIA. - Ken Ken-JP wrote: > > Hi, > > I saw this example for 2.10 Time series in the xtable gallery > documentation. > > http://cran.r-project.org/web/packages/xtable/vignettes/xtableGallery.pdf > > How would I add a column at the end "Total" which sums the row, with > minimal changes to the code below? > > Thanks in advance. > > - Ken > > 2.10 Time series >> temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)), start = c(1954, > + 7), frequency = 12) >> temp.table <- xtable(temp.ts, digits = 0) >> caption(temp.table) <- "Time series example" >> print(temp.table, floating = FALSE) > > Time series example > Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec > 1954 2 3 6 8 11 10 > 1955 11 13 15 16 16 18 20 22 21 22 24 24 > 1956 25 26 28 28 28 28 29 31 31 32 33 34 > 1957 35 36 38 39 39 41 42 42 41 42 43 45 > 1958 46 46 47 47 49 51 54 56 58 59 61 61 > 1959 62 61 62 62 62 63 62 64 64 66 67 68 > 1960 67 67 69 71 74 75 77 78 79 80 82 81 > 1961 84 86 87 88 89 91 94 94 94 94 96 97 > 1962 98 99 101 102 104 105 108 107 106 107 > > > -- View this message in context: http://www.nabble.com/xtable---how-to-add-a-%22sum-of-values-in-a-row%22-column--tp25635552p25643331.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] xtable - how to add a "sum of values in a row" column?
Fantastic! I didn't know about addmargins()... It looks like with FUN=myfunc, I can make it do all sorts of fun calculations over the row. TYVM - Ken Henrique Dallazuanna wrote: > > Try this: > > temp.table <- xtable(temp.ts, digits = 0) > temp.table <- xtable(addmargins(as.matrix(as.data.frame(temp.table)), > 2), digits = 0) > > On Sun, Sep 27, 2009 at 2:24 PM, Ken-JP wrote: >> >> Hi, >> >> I saw this example for 2.10 Time series in the xtable gallery >> documentation. >> >> http://cran.r-project.org/web/packages/xtable/vignettes/xtableGallery.pdf >> >> How would I add a column at the end "Total" which sums the row, with >> minimal >> changes to the code below? >> >> Thanks in advance. >> >> - Ken >> >> 2.10 Time series >>> temp.ts <- ts(cumsum(1 + round(rnorm(100), 0)), start = c(1954, >> + 7), frequency = 12) >>> temp.table <- xtable(temp.ts, digits = 0) >>> caption(temp.table) <- "Time series example" >>> print(temp.table, floating = FALSE) >> >> Time series example >> Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec >> 1954 2 3 6 8 11 10 >> 1955 11 13 15 16 16 18 20 22 21 22 24 24 >> 1956 25 26 28 28 28 28 29 31 31 32 33 34 >> 1957 35 36 38 39 39 41 42 42 41 42 43 45 >> 1958 46 46 47 47 49 51 54 56 58 59 61 61 >> 1959 62 61 62 62 62 63 62 64 64 66 67 68 >> 1960 67 67 69 71 74 75 77 78 79 80 82 81 >> 1961 84 86 87 88 89 91 94 94 94 94 96 97 >> 1962 98 99 101 102 104 105 108 107 106 107 >> >> >> -- >> View this message in context: >> http://www.nabble.com/xtable---how-to-add-a-%22sum-of-values-in-a-row%22-column--tp25635552p25635552.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> R-help@r-project.org mailing list >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- View this message in context: http://www.nabble.com/xtable---how-to-add-a-%22sum-of-values-in-a-row%22-column--tp25635552p25648849.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] dichromat, regexp, and grid objects
baptiste auguie googlemail.com> writes: > Replying to myself here, > Hadley pointed out this website on the ggplot2 mailing list, > > http://colororacle.cartography.ch/ > > And this seems like a more straight-forward solution to my query > (albeit not using R). It sort of makes sense to momentarily alter the > computer display rather than parse the code for colour and fill > regular expressions... > 2009/9/28 baptiste auguie googlemail.com>: > > Dear list, > > The dichromat package defines a dichromat function which "Collapses > > red-green color distinctions to approximate the effect of the two > > common forms of red-green colour blindness, protanopia and > > deuteranopia." > > All the best, > > > > baptiste Just to point out a fact or two with respect to the information on the indicated web page and a statement above. While roughly 8% of males are classified as color-deficient by standard tests, as indicated at the site to which the link points, only about 2% are actually dichromats, i.e., protanopes and deuteranopes, referred to above as "common forms", and to which the dichromat package is directly relevant. Dichromatic vision is reduced to 2 dimensions from the normal 3. Most of the other 6% (i.e., the most common forms) are what are termed anomalous trichromats and to whom the renditions of the dichromat package are not actually appropriate, as the color spaces of such observers are not a subspace of that of a normal observer. Such individuals really see the world a bit differently, as they may very well call something as red that a normal observer would call green or vice versa depending what kind of anomalous trichromat one is. So, strictly speaking, the dichromat package is of great value in avoiding color choices that about 1% of the population would have trouble discriminating. Ken -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 do I name data frames and files according to the index of a for loop?
Thanks in advance for reading my question. This is my first time working with R, though I have some intro-level experience with other languages. I am writing a program that performs a certain set of calculations on each row of a list of data, and here's what I have so far: for (i in 1:2858) { Calc_1 <- some_stuff Calc_2 <- some_more_stuff Calc_3 <- some_other_stuff Data_frame_name <- data.frame(Calc_1, Calc_2, Calc_3) write.table(Data_frame_name,file="~/file/goes/here.csv", append = FALSE, sep = "\t",row.names = FALSE, col.names = c("Calc_1", "Calc_2", "Calc_3"),qmethod = "double") } The naming of the data frame and the writing of the file go swimmingly, if I do it ONCE, outside of the for loop. I want to embed the process in the for loop written above, run it 2858 times, and get that many data frames and .csv files that I can then manipulate. In order to do so, I would like to name the data frames and/or files by their respective index, to get: Data_frame_name1 Data_frame_name2 Data_frame_name3 ... Data_frame_name2858 I would also like to produce the .csv files: ~/file/goes/here1.csv ~/file/goes/here2.csv ~/file/goes/here3.csv ... ~/file/goes/here2858.csv I've been noodling over this for a while and have looked all over but I can't seem to get the syntax right. Any help at all would be appreciated. Thanks again! -Ken Ervin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] reshaping data
Hi all, I have a matrix of correlation values between all pairwise comparison in an experiment. For example, I have 2 time points (1,2) each in triplicate. Thus, I have the following matrix 1-1 1-2 1-3 2-1 2-2 2-3 1-1 NA ... ... ... ... ... 1-2 ... NA ... ... ... ... 1-3 ... ... NA ... ... ... 2-1 ... ... ... NA ... ... 2-2 ... ... ... ... NA ... 2-3 ... ... ... ... ... NA What I'd like to do is to reshape the data so that it would be easy for me to summarize all the correlation values across the triplicates (i.e. mean) for time point 1 and 2. It sounds as though the reshape package should be able to do this, but the solution is not obvious to me. Can anybody help? Best, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] FW: reshaping data
I apologize for the previous post using HTML. Haven't posted for a while and e-mail client default. Best, Ken Hi all, I have a matrix of correlation values between all pairwise comparison in an experiment. For example, I have 2 time points (1,2) each in triplicate. Thus, I have the following matrix 1-1 1-2 1-3 2-1 2-2 2-3 1-1NA ... ... ... ... ... 1-2... NA ... ... ... ... 1-3... ... NA ... ... ... 2-1... ... ... NA ... ... 2-2... ... ... ... NA ... 2-3... ... ... ... ... NA What I'd like to do is to reshape the data so that it would be easy for me to summarize all the correlation values across the triplicates (i.e. mean) for time point 1 and 2. It sounds as though the reshape package should be able to do this, but the solution is not obvious to me. Can anybody help? Best, Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 do I plot a regression curve with the data?
I have a data set of 6 or so ordered pairs, and I've been able to graph them and have decided to use a high-order polynomial regression. I've used the following piece of code: regression <- function(x,y) { x <- c(insert_numbers_here) y <- c(insert_other_numbers_here) fit <- lm(y ~ x + I(x^2) + I(x^3) + I(x^4) + I(x^5) + I(x^6) + I(x^7) + I(x^8) + I(x^9)) summary(fit) This gives me the coefficients for the regression very nicely, but I would like to plot both the data and the regression curve together. How do I plot that regression curve as a function, and can I put it on the same set of axes as my data scatter plot? Thanks in advance for your help! -KE __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] design matrix construction question
> On Nov 2, 2009, at 10:40 PM, Ben Bolker wrote: > > with the following simple data frame > > dd = structure(list(z = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L > > ), .Label = c("a", "b"), class = "factor"), x = c(0.3, 0.2, 0.1, > > 0, 0, 0, 0.2, 0.3)), .Names = c("z", "x"), row.names = c(NA, > > -8L), class = "data.frame") > > > > I would like know if it's possible to use model.matrix() > > to construct the following design matrix in some sensible way: > > > > za zb > > 1 1 0 > > 2 1 0 > > 3 1 0 > > 4 0 0 > > 5 0 0 > > 6 0 0 > > 7 0 1 > > 8 0 1 How about something like this? dd$xf <- (dd$x > 0) + 0 model.matrix(~ z:xf - 1, dd) za:xf zb:xf 1 1 0 2 1 0 3 1 0 4 0 0 5 0 0 6 0 0 7 0 1 8 0 1 attr(,"assign") [1] 1 1 attr(,"contrasts") attr(,"contrasts")$z [1] "contr.treatment" > > thanks > > Ben Bolker > > > > -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Setting column widths in heatmap
Hello, I cannot figure out how to set the column widths (either relative or absolute) for the heatmap function - the full manual hints that layout and lcm will control this, but I haven't had any luck. This is in R 2.9.2 compiled for either FC10 or SUSE11.1 (x86_64)... and am sending the output of heatmap to the pdf driver. Thanks in advance! -kt _ Hotmail: Trusted email with Microsoft's powerful SPAM protection. [[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] How do I run to or more R consoles on Mac OS X?
chronos.phenomena gmail.com> writes: > > > This is really annoying me... when I click R application icon it brings > already opened session in the focus and it DOESN'T open new session > > any ideas? In Leopard from a terminal, you can try open -n /Applications/R.app to open as many copies of the app as you like. Be careful though, because these inherit environment variables from the terminal session, not necessarily the same as those when running the app from the Finder. I was bitten by that the first time I tried this. Ken -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Getting Rd pages right for redefined S3 generic
S Ellison lgc.co.uk> writes: > I wanted to define a cbind equivalent for an object that mostly behaves > like a data frame. base::cbind dispatches to a data frame method if > _any_ parameter is a data frame, so I defined a new S3 cbind and > cbind.default to handle dispatch on first object only. Though I confess > that redefining cbind leaves me a tad nervous, that all works OK so far. clipped --- > Steve Ellison Why don't you just define a method for your object class. It should dispatch on your method if all of the objects that you give it have that class. I did this in the MLDS package in a situation in which I had a data frame that had additional attributes and I wanted rbind (in my case) to concatenate the attributes as well as the actual data frame. I gave the data frame with these extra attributes the class of c("mld.df", "data.frame") so that they would still inherit other data frame methods. My rbind.mlds.df works fine with them, and I document it accordingly. HTH. Ken -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with expand.grid
Keith Jewell campden.co.uk> writes: > > Hi All, > > This example code > > dDF <- structure(list(y = c(4.75587, 4.8451, 5.04139, 4.85733, 5.20412, > 5.92428, 5.69897, 4.78958, 4, 4), t = c(0, 48, 144, 192, 240, > 312, 360, 0, 48, 144), Batch = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1 > ), T = c(2, 2, 2, 2, 2, 2, 2, 2, 2, 2), pH = c(4.6, 4.6, 4.6, > 4.6, 4.6, 4.6, 4.6, 4.6, 4.6, 4.6), S = c(0, 0, 0, 0, 0, 0, 0, > 0, 0, 0), N = c(0, 0, 0, 0, 0, 0, 0, 80, 80, 80)), .Names = c("y", > "t", "Batch", "T", "pH", "S", "N"), row.names = c(NA, 10L), class = > "data.frame") > str(dDF) > expand.grid(dDF) > > 'hangs' for a while and then gives an error or even simpler expand.grid(data.frame(1:3, 1:3)) Error in `[[<-.data.frame`(`*tmp*`, i, value = c(1L, 2L, 3L, 1L, 2L, 3L, : replacement has 9 rows, data has 3 but why do this on a data frame as it works fine on a list expand.grid(list(1:3, 1:3)) Var1 Var2 111 221 331 412 522 632 713 823 933 or just vectors expand.grid(1:3, 1:3) Var1 Var2 111 221 331 412 522 632 713 823 933 -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Converting data.frame to xts
I have a data.frame object and I don't really understand how to made an xts class out of it. Consider: > x <- data.frame(datetime, ltp, ltv) > head(x, 2) datetime ltp ltv 1 2009-05-05 07:30:01.604 899 1 2 2009-05-05 07:30:01.963 899 15 > class(x$datetime) [1] "POSIXt" "POSIXct" #This works for only one column and why do I lose the name of that column? > x0 <- xts(x$ltp, x$datetime) > head(x0, 2) [,1] 2009-05-05 07:30:01.604 899 2009-05-05 07:30:01.963 899 #The POSIXct gets indexed but then there are these 3 columns of character strings...??? > x1 <- xts(x, x$datetime) > head(x1, 2) datetime ltp ltv 2009-05-05 07:30:01.604 "2009-05-05 12:30:01.604" "899.00" " 1" 2009-05-05 07:30:01.963 "2009-05-05 12:30:01.963" "899.00" " 15" #Same output as x1 above > x2 <- as.xts(x, order.by = x$datetime, datetime="POSIXct", frequency=NULL) > head(x2, 2) datetime ltp ltv 2009-05-05 07:30:01.604 "2009-05-05 12:30:01.604" "899.00" " 1" 2009-05-05 07:30:01.963 "2009-05-05 12:30:01.963" "899.00" " 15" #Wishing it were this easy... :) > x3 <- as.xts(x) Error in as.POSIXlt.character(x, tz, ...) : character string is not in a standard unambiguous format -- View this message in context: http://www.nabble.com/Converting-data.frame-to-xts-tp23817648p23817648.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] Splicing factors without losing levels
Titus von der Malsburg gmail.com> writes: > An operation that I often need is splicing two vectors: > > splice(1:3, 4:6) > [1] 1 4 2 5 3 6 > For numeric vectors I use this hack: > splice <- function(x, y) { > xy <- cbind(x, y) > xy <- t(xy) > dim(xy) <- length(x) * 2 > return(xy) > } > So far, so good (?). But I also need splicing for factors and I tried > this: > > splice <- function(x, y) { > xy <- cbind(x, y) > xy <- t(xy) > dim(xy) <- length(x) * 2 > if (is.factor(x) && is.factor(y)) { > xy <- as.factor(xy) > levels(xy) <- levels(x) > } > return(xy) > } > This, however, doesn't work because the level name to integer mapping > gets mixed up when copying the levels from x to xy. > Thanks!! > Titus How about something like;: splice.factor <- function(x, y){ if (!(is.factor(x) & is.factor(y))) stop("Both x and y must be factors") if (length(x) != length(y)) stop("Both x and y must have same length") lx <- levels(x) ly <- levels(y) lxy <- union(lx, ly) xy <- cbind(levels(x)[x], levels(y)[y]) xy <- t(xy) dim(xy) <- NULL xy <- factor(xy, levels = lxy) xy } > splice.factor(factor(1:3), factor(4:6)) [1] 1 4 2 5 3 6 Levels: 1 2 3 4 5 6 -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] overshoot of formula line in summary output of Sweave
Hi, In the Sweave output for summary for several types of model objects and also for the comparison of models with anova, I find that that the display of the call(s) or formula does not obey the width option, even with keep.source=TRUE set, so that a long formula will overshoot the margins in the document. I would like to know if there is a good way to correct that. Looking at the print.summary methods for lm, glm and several others, I see that a construct like deparse(obj$call) is used to generate the text. The deparse function takes a "width.cutoff" argument, that could be used in these cases, if it were possible to pass a value to it, or if its default value could be set with an option. Other methods do not use deparse, (print.summary.polr in MASS uses dput and anovalist.nls also does it differently) so such a solution would not work universally without altering these functions. Here is a toy example that illustrates the overshoot of the formula \documentclass[12pt]{article} \usepackage{geometry} \geometry{left=2in,right=2in} \begin{document} <>= op <- options(width = 65, digits = 3) ddataframe <- data.frame(A = 1:10, B = factor(letters[1:2]), C = factor(LETTERS[1:5]), S = factor(paste("S", 1:10, sep = "")), R = rnorm(10)) mod1 <- lm(R ~ A + B + C + S, ddataframe) summary(mod1) @ \end{document} I have attached the pdf output. Thanks, in advance, for any suggestions. Ken -- Ken Knoblauch Inserm U846 Stem-cell and Brain Research Institute Department of Integrative Neurosciences 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr/members/kenneth-knoblauch.html TmpTest.pdf Description: Adobe PDF document __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] overshoot of formula line in summary output of Sweave
Ben Bolker ufl.edu> writes: > > In the Sweave output for summary for several types > > of model objects and also for the comparison of models > > with anova, I find that that the display of the call(s) > > or formula does not obey the width option, even with > > keep.source=TRUE set, so that a long formula will overshoot > > the margins in the document. I would like to know if > > there is a good way to correct that. Looking at the > > print.summary methods for lm, glm and several others, > > I see that a construct like deparse(obj$call) is used > > to generate the text. The deparse function takes a > > "width.cutoff" argument, that could be used in these cases, > > if it were possible to pass a value to it, or if its default > > value could be set with an option. Other methods do not > > use deparse, (print.summary.polr in MASS uses dput and > > anovalist.nls also does it differently) so such a solution > > would not work universally without altering these functions. > > > > Here is a toy example that illustrates the overshoot of the formula > > > > \documentclass[12pt]{article} > > \usepackage{geometry} > > \geometry{left=2in,right=2in} > > \begin{document} > > <>= > > op <- options(width = 65, digits = 3) > > ddataframe <- data.frame(A = 1:10, > > B = factor(letters[1:2]), > > C = factor(LETTERS[1:5]), > > S = factor(paste("S", 1:10, sep = "")), > > R = rnorm(10)) > > > > mod1 <- lm(R ~ A + B + C + S, > > ddataframe) > > summary(mod1) > > @ > > \end{document} > > A quick guess: try keep.source=TRUE and format your commands > as you would like to see them appear ... > > Ben Bolker Thanks, Ben, for the response. As you can see, in the example above, I did use keep.source=TRUE. I can always format it by hand in the final document, but I was looking for an automatic formating solution, if it was something obvious or not that I have missed. It seems to me that the problem is in print.summary and anova methods. For lm and glm, they use deparse(obj$call). deparse takes a width.cutoff argument, which is set by default to 60L, but you can't access it directly from the summary or anova arguments. It's a bit heavy-handed, but a solution is to change the default value of width.cutoff in base, using assignInNamespace. Making my own deparse in the workspace doesn't work because the base functions don't see it.Other methods don't necessarily use deparse. I've seen a few that use dput(), which doesn't have a width argument, so I'm losing hope of finding a general, automatic solution. Thanks, in any case. Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] overshoot of formula line in summary output of Sweave
Ben Bolker ufl.edu> writes: > >> > Here is a toy example that illustrates the overshoot of the formula > >> > \documentclass[12pt]{article} > >> > \usepackage{geometry} > >> > \geometry{left=2in,right=2in} > >> > \begin{document} > >> > <>= > >> > op <- options(width = 65, digits = 3) > >> > ddataframe <- data.frame(A = 1:10, > >> > B = factor(letters[1:2]), > >> > C = factor(LETTERS[1:5]), > >> > S = factor(paste("S", 1:10, sep = "")), > >> > R = rnorm(10)) > >> > > >> > mod1 <- lm(R ~ A + B + C + S, > >> > ddataframe) > >> > summary(mod1) > >> > @ > >> > \end{document} > >> A quick guess: try keep.source=TRUE and format your commands > >> as you would like to see them appear ... > >> Ben Bolker > > Thanks, Ben, for the response. --- deleted text --- > > I wonder if there is a LaTeX-side solution, i.e. constructing a > verbatim-like environment that breaks lines? It sounds a bit like an oxymoron but isn't that more or less what Sweave does when keep.source is not set to TRUE, only it doesn't seem to catch the print-outs of these long calls. I'll give your suggestion some further thought, however. Thanks. Ken __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Roxygen vs Sweave for S4 documentation
Hi, I have been using R for a while. Recently, I have begun converting my package into S4 classes. I was previously using Rdoc for documentation. Now, I am looking to use the best tool for S4 documentation. It seems that the best choices for me are Roxygen and Sweave (I am fine with tex). Are there any users of Roxygen or Sweave who can comment on the strengths or weaknesses of one or othe other? Thanks in advance. - Ken -- View this message in context: http://www.nabble.com/Roxygen-vs-Sweave-for-S4-documentation-tp24131590p24131590.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] Roxygen to ignore a block of code?
Any way to tell Roxygen to ignore a block of code? It is generating an unwanted .Rd file. I've been searching for hours for an example, scouring documentation, but no luck... Thanks. - Ken -- View this message in context: http://www.nabble.com/Roxygen-to-ignore-a-block-of-code--tp24133293p24133293.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] Roxygen to ignore a block of code?
For instance, I am trying to run Roxygen on: require( zoo ) # needed for time series setClass( "zoo" ) # lets S4 know about S3 class so we can use as an argument setClass( "myClass", representation( .zoo="zoo" ), prototype( 0, as.Date("1970-01-01") )) When I run this code through Roxygen, it warns: > No name found for the following expression: require( zoo ) and generates zoo.Rd - I don't want any zoo.Rd to be generated - I am a user of the library, not an implementer. 1. How can I tell Roxygen NOT to generate zoo.Rd? 2. What do I do to prevent Roxygen from warning about: require( zoo ) ? Thx. - Ken -- View this message in context: http://www.nabble.com/Roxygen-to-ignore-a-block-of-code--tp24133293p24137672.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] 'require' equivalent for local functions
I agree with Duncan. I used to do exactly what you did - source()ing data files inside a wrapper not unlike C #define wrappers, but it became a headache with more files and the files began looking more cluttered. It has taken me several days to learn about how create a package properly, along with package RUnit for unit-testing, and with documentation. The "R Extensions" file is often a good source of information. Be sure you find information about Rcmd install and Rcmd check, which are also very useful. prompt() can help you build your .Rd (help files). Alternatively, you may use Rdoc$compile() (from package R.oo) if you intend to embed your Rdoc-style comments inside your R code, as I do. I also use R.oo as a more traditional object-oriented alternative to S3/S4. Once set-up, you can automagically generate .pdf files and .chm (windows-based help) for your package. Help for my own package has helped me keep my code consistent, clean, and re-factorable. Best of all, you can use put require( my.package ) or data( my.data) and voila. It has been a bit of a learning curve, but the packaging facilities in R are actually very well developed. Once set-up, maintenance becomes less of a chore. Good luck. Duncan Murdoch-2 wrote: > > On 22/03/2009 5:05 PM, JiHO wrote: >> Hello everyone, >> >> I often create some local "libraries" of functions (.R files with only >> functions in them) that I latter call. In scripts that call a function >> from such library, I would like to be able to test whether the >> function is already known in the namespace and, only if it is not, >> source the library file. I.e. what `require` does for packages, I want >> to do with my local functions. > > That's pretty hard to make bulletproof. Why not just put those > functions in a package, and use that package? If the functions are all > written in R, creating the package is very easy: see package.skeleton. > (And if you have a perfect memory and don't plan to distribute the > package to anyone, you can skip documenting the functions: then it's > almost no work at all.) > -- View this message in context: http://www.nabble.com/%27require%27-equivalent-for-local-functions-tp22650626p22653884.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] performance: zoo's rollapply() vs inline
zoo's rollapply() function appears to be extremely useful for plugging in a function on-the-fly to run over a window. With inline, there is a lot more coding and room for error, and the code is less portable because the user has to have R compiling set up or it won't work. However, rollapply() seems to be really slow. Several orders of magnitude slower than inline, in fact. I don't know how to call R functions from C inline yet, but it looks like I need to learn, because the speed difference is just way too big. The results of a quick test are shown below. I am totally open to suggestions on how to do windowed calculations, in general, but it looks like I may have to bite the bullet and learn all the intricacies of calling R from C. NOTE: pchg.inline() is not shown because it's much longer/complex than pchg.rollapply(), but I am doing no optimizations. pchg.rollapply <- function(this, m, shift=1, ...) { rollapply( m, shift+1, function(x) { x[shift+1]/x[1] - 1; }, align="right" ); } > dim( m ) [1] 4518 800 > system.time( x.rollapply <- pchg.rollapply( m, 20 ) ) user system elapsed 146.940.81 157.03 > system.time( x.inline<- pchg.inline( m, 20 ) ) user system elapsed 0.690.000.72 -- View this message in context: http://www.nabble.com/performance%3A--zoo%27s-rollapply%28%29-vs-inline-tp22656214p22656214.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] Converting a Matrix to a Vector
Say I have: > set.seed( 1 ) > m <- matrix( runif(5^2), nrow=5, dimnames = list( c("A","B","C","D","E"), > c("O","P","Q","R","S") ) ) > m O P Q R S A 0.2655087 0.89838968 0.2059746 0.4976992 0.9347052 B 0.3721239 0.94467527 0.1765568 0.7176185 0.2121425 C 0.5728534 0.66079779 0.6870228 0.9919061 0.6516738 D 0.9082078 0.62911404 0.3841037 0.3800352 0.121 E 0.2016819 0.06178627 0.7698414 0.7774452 0.2672207 --- I want to create a vector v from matrix m that looks like this: A.O 0.2655087 B.O 0.3721239 v <- as.vector( m ) almost gives me what I want, but then I need to take combinations of colnames( m ) and rownames( m ) to get my labels and hope they match up in order: if not, manipulate the order. This approach feels kludgy... Is this the right approach or is there a better way? -- View this message in context: http://www.nabble.com/Converting-a-Matrix-to-a-Vector-tp22696267p22696267.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] Doing %o% that operates on columns instead of atomics
Okay, this one is hard to put into words: > x <- 1:9; names(x) <- x > y <- x %o% x > y 1 2 3 4 5 6 7 8 9 1 1 2 3 4 5 6 7 8 9 2 2 4 6 8 10 12 14 16 18 3 3 6 9 12 15 18 21 24 27 4 4 8 12 16 20 24 28 32 36 5 5 10 15 20 25 30 35 40 45 6 6 12 18 24 30 36 42 48 54 7 7 14 21 28 35 42 49 56 63 8 8 16 24 32 40 48 56 64 72 9 9 18 27 36 45 54 63 72 81 > my.foo( a, b ) { c <- a - b; #really more complex, but just to illustrate > } - What I would like to do is apply my.foo() which takes two columns, a and b, does an operation and returns another column c. The columns I want to feed into my.foo() are all the combinations of columns in y. So I want to apply my.foo( y[,1], y[,1] ) and then my.foo( y[,1], y[,2] ), etc... for all combinations() of the 10 columns in y. I would expect the final output to be 10x10x10. Passing 10 columns by 10 columns to my.foo() which outputs a vector of 10 numbers at a time. ***So in essence, what I am trying to accomplish is like outer(), but instead of operating on atomic values, I want to operate on columns of y. I know I can use loops to accomplish this, but I would like to code as R-like as possible. I am learning a great deal about "how to think in R" from the excellent replies on this board. Thanks in advance for any suggestions. -- View this message in context: http://www.nabble.com/Doing--o--that-operates-on-columns-instead-of-atomics-tp22701363p22701363.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] Doing %o% that operates on columns instead of atomics
CORRECTION: > my.foo <- function( a, b ) { c <- a - b; } #really more complex, but just > to illustrate -- View this message in context: http://www.nabble.com/Doing--o--that-operates-on-columns-instead-of-atomics-tp22701363p22701400.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] Error Running TinnR with R
I had all these headaches with Tinn-R on Vista - tried reading all the message boards, reconfiguring .Rprofile, etc... ...no luck. I finally gave up and started using Eclipse with StatET. Now, it's actually easier to run RCMDs to check and release a package, and with SVN integration in Eclipse (with a plug-in), it's also easier to check code in and out. The only drawback is, the font-coloring isn't as nice as Tinn-R, but that's configurable - I will set it up to color like Tinn-R. -- View this message in context: http://www.nabble.com/Error-Running-TinnR-with-R-tp19477151p22753954.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] Eclipse and StatET Howto (also added Subversion, Rtools)
I recently got a RFC on Eclipse and StatET setup from a R-help user, so here it is. Note: there may be slight errors of omission in my directions as I am making these notes after I had a successful install. If you have questions post here. Setup tested with Eclipse 3.4.0 on XP 32-bit and Eclipse 3.4.2 on Vista 32-bit. R 2.9.0 alpha. Installing StatET: 1. Go to Help > Software Updates... > Available Software > Add Site... > and type in: http://download.walware.de/eclipse-3.4 2. Select the packages you want and Install 3. Restart Eclipse - if successful, you should see StatET under Window Preferences... 4. Go to Window > Preferences > StatET > R Environments > Add... and enter a label for your R environment (eg R 2.9.0 alpha) and path (eg L:/bin/R/R-2.9.0alpha ) NOTE: I had some flaky issues with sending code in StatET when my path included spaces, so if you have issues, it is best to reinstall R in a path that contains no spaces. 5. In Eclipse, click on the Add Views icon in your toolbar and select Other > StatET 6. In Eclipse, click on the Green Play Array Icon/Menu and and select Run Configurations... 6a. Enter a name for your run configuration (eg R 2.9.0 alpha ) 6b. Under the R Config tab, you should see your entry in 4. under Workbench default 6c. Enter a Working Directory, if you like 7. Reference for more details: http://www.splusbook.com/Rintro/R_Eclipse_StatET.pdf Installing Subversion (SVN Client): WARNING: Trust Tigris and their 0.7 & post 1.4-releases at your own risk. I spent several hours trying to get later versions to work, but they all failed to recognize SVNKit on my setups. Several other users have posted this issue. The solution is to install 1.4, which I will describe here. I assume that you already have an svn server setup on svn://svnserver 1. Help > Software Updates... > Add Site... > http://subclipse.tigris.org/update_1.4.x 2. Pick the packages you want (pay attention to required ones) and install 3. Right-Click on Project Explorer > Import > SVN > Checkout Projects from SVN > Next 4. Create a new repository location > type in something like svn://svnserver/subdir > Next 5. Select the folders you want > Finish IMPORTANT if you have problems with any version of Subversion: Check: Windows > Preferences > Team > SVN > SVN Interface or: Windows > Preferences > Team > SVN > Client Connectors Tab to make sure that under SVN Interface or Client Interface (depending on the version of the plug-in) that you have JavaHL (what I use) or SVNKit. If not, these could be the reasons: 1. You didn't select the interface package during the install 2. You are using a post 1.4 version (eg 0.7 or 1.5 and later) Installing RTools/HTML Compiler for Windoze users: This is useful for users of package inline or for users who want to compile their own packages using Rcmd 0. NOTE: you need to install perl and some tex (I use MikTex) before you install Rtools - follow their instructions. 1. Go to: http://www.murdoch-sutherland.com/Rtools/installer.html 2. Get Microsoft's HTML Compiler (to create chm) here: http://msdn.microsoft.com/en-us/library/ms669985(VS.85).aspx It's called htmlhelp.exe and includes hhc.exe 3. Follow instructions: important point - you should set your path to include RTools and you RHome/bin and to hhc directory (eg L:\Program Files\HTML Help Workshop\) 4. Test under Windows/cmd to make sure your setup works properly (eg Rcmd --help) If you manage to get RCmd working, you can go back to Eclipse and do this: 1. Click on Green Play Arrow With Red toolbox Menu > External Tools Configuration 2. In Package directory enter something like L:/dev/workspace/mypackage 3. IMPORTANT: Under Command: pick the right one! Like Add-On Package: Build In a small box to the right, you will see the RCMD to be executed. You DO NOT need to enter the name of your package under Options/Arguments - basically type everything here EXCEPT the name of your package. 4. CHECK if something is wrong: In the R Config tab, you should have your correct R Environment picked (eg R 2.9.0 alpha) - this is how the system knows which path to use to get to RCmd I hope someone finds this useful. Good luck! -- View this message in context: http://www.nabble.com/Eclipse-and-StatET-Howto-%28also-added-Subversion%2C-Rtools%29-tp22764049p22764049.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] Excellent Talk on Statistics (Good examples of stat. visualization)
with very good examples of statistical visualization. "Talks Hans Rosling: Debunking third-world myths with the best stats you've ever seen" http://www.ted.com/index.php/talks/hans_rosling_shows_the_best_stats_you_ve_ever_seen.html -- View this message in context: http://www.nabble.com/Excellent-Talk-on-Statistics-%28Good-examples-of-stat.-visualization%29-tp22785778p22785778.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] [tcl] unknown color name "red" errors
I am running on 64-bit Ubuntu, R version 2.8.1 If I do anything Tcl/Tk related like: > library( Rcmdr ) or > available.packages() I get the error: Error in structure(.External("dotTclObjv", objv, PACKAGE="tcltk"), class = "tclObj") : [tcl] unknown color name "red" - I am starting R from a terminal - is this the problem? Should I be running it directly from KDE somehow? -- View this message in context: http://www.nabble.com/-tcl--unknown-color-name-%22red%22-errors-tp22845915p22845915.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] (SOLVED) Re: [tcl] unknown color name "red" errors
On the boards for Ubuntu 8.10 64-bit, there were comments along the lines that: /etc/X11/rgb.txt was missing. However, even after I replace this file, and logged back out in, this problem went away. It's shocking that a file as old/basic as /etc/X11/rgb.txt can be removed - I'm sure a lot of programs depend on it. -- View this message in context: http://www.nabble.com/-tcl--unknown-color-name-%22red%22-errors-tp22845915p22880689.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] Eclipse and StatET Howto (also added Subversion, Rtools)
An update: after several days of struggling, I got StatET to work on Ubuntu 8.10 amd64, R 2.8.1. Here are some tips: 1. You may run into an X11 issue with tktcl in R as someone decided to omit /etc/X11/rgb.txt If you get weird issues with your R installation with window colors like "red" or "black", then you may be missing this file. Retrieve a copy off the web, and log in/out or restart your X. 2. When installing packages into R >DO NOT< use sudo or you will run into problems later on - particularly if your R packages automatically install into /home/myname/R/x86_64-pc-linux-gnu-library/2.8 3. I read of many problems with OpenJDK so uninstall that and install Sun's JDK instead (I think rJava may need Sun's JDK). Google around for instructions - it was safer to remove OpenJDK first. Make sure you get something reasonable when you do "java -version" and "R CMD javareconf" 4. Make sure you install the package rJava to completion - the system will build it ***5. Under Run configurations>JRE>VM Arguments you need something like this: -Drjava.path=/home/myname/R/x86_64-pc-linux-gnu-library/2.8/rJava I lost many hours with 5., but of course I didn't RTFM!!! Didn't need this one for Windoze, but needed it for Ubuntu. http://www.walware.de/goto/statet near the bottom... Note: There were probably other small steps during the install, but I didn't keep track. However, all solutions were found through googling... Of course, the advantage is, under amd64, we are no longer limited to 3GB of memory for R. Good luck! -- View this message in context: http://www.nabble.com/Eclipse-and-StatET-Howto-%28also-added-Subversion%2C-Rtools%29-tp22764049p22887711.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] Eclipse and StatET Howto (also added Subversion, Rtools)
Yes, I have x11-common installed, and dpkg -S /etc/X11/rgb.txt shows "not found" for me. This is on Ubuntu 8.10 amd64. http://ubuntuforums.org/archive/index.php/t-59024.html Thanks for the detailed explanation on how R decides on where to install packages! I think I ran into problems when I haphazardly intermixed "sudo R" with "R" before installing packages. - BTW, is there a way to install all packages via: > install.packages(available.packages()[,1]) for Ubuntu without building everything? I noticed quite a few errors when I tried this - build problems probably mostly due to missing installations in the OS. It was much nicer when I tried this on Windoze, and everything was pulled in cleanly and quickly. Is there a reason that packages seem to be in r-cran-XXX via "apt-get install" for Ubuntu? There must be an obvious reason that I don't know about... Thanks for taking the time to answer. - Ken -- View this message in context: http://www.nabble.com/Eclipse-and-StatET-Howto-%28also-added-Subversion%2C-Rtools%29-tp22764049p22888024.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] showing values in levelplot or image
I am trying to visualize a 2D matrix, with some auxiliary labels associated with each rectangle in the chart. The image command and levelplot in the lattice package map data to colors, but I couldn't find any option to specify values I want to show. Is there an easy way to do this? Thanks, Ken [[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] Eclipse and StatET Howto (also added Subversion, Rtools)
Peter Dalgaard wrote: > > Hum.. Fedora 9 doesn't have it either. > > It does have /usr/share/X11/rgb.txt though, so please check whether it > has moved. I'm curious as to why (only) R/tcltk would be confused by > this sort of thing. > If you check here: https://bugs.launchpad.net/ubuntu/+source/xorg/+bug/300935 You will find many other unhappy apps: emacs xterm vnc freeNX netpbm x3270 stage and any others that uses names in place of rgb codes for X11. Like one of the posters said, I don't care for arguing whether or not the file should be made obsolete or not. All I know is, removing it breaks some very basic programs. - Ken -- View this message in context: http://www.nabble.com/Eclipse-and-StatET-Howto-%28also-added-Subversion%2C-Rtools%29-tp22764049p22892507.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] Need Help with StatET Error/Bug? on Ubuntu 8.10 amd64
Hi, I posted this message on the StatET-user board last week, but it looks like a ghost-town... I have a bad feeling that there is some code in the plug-in which doesn't work well with my environment, but if I am lucky, maybe other users have worked around this problem somehow - I am hoping that my setup is the issue. Note: very similar StatET setups on 32-bit XP Pro and Vista run flawlessly. Has anyone else run into this problem and/or found a way around it? Ubuntu 8.10 intrepid amd64 Java(TM) SE Runtime Environment (build 1.6.0_13-b03) Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02, mixed mode) R 2.8.1 Eclipse 3.4.2 StatET 0.7.2.b200812051430sw When I start up the R Console, I get a java.lang.NullPointerException inside Eclipse in the form of a popup warning. Six icons right of the Console-tab fail to appear: Cancel the current task Terminate Remove Launch Remove All Terminated Launches Clear Console Scroll Lock Every time the Console gets focus, I get the NullPointerError exception - probably an attempt to refresh the icons. After a while, the Eclipse IDE loses focus and becomes unusable. Looks like it's happening around: at org.eclipse.ui.SubActionBars.updateActionBars(SubActionBars.java:610) Session Data: eclipse.buildId=M20090211-1700 java.version=1.6.0_13 java.vendor=Sun Microsystems Inc. BootLoader constants: OS=linux, ARCH=x86_64, WS=gtk, NL=en_US Command-line arguments: -os linux -ws gtk -arch x86_64 Exception Stack Trace: java.lang.NullPointerException at org.eclipse.jface.resource.URLImageDescriptor.getFilePath(URLImageDescriptor.java:138) at org.eclipse.jface.resource.URLImageDescriptor.createImage(URLImageDescriptor.java:157) at org.eclipse.jface.resource.ImageDescriptor.createResource(ImageDescriptor.java:165) at org.eclipse.jface.resource.DeviceResourceManager.allocate(DeviceResourceManager.java:56) at org.eclipse.jface.resource.AbstractResourceManager.create(AbstractResourceManager.java:88) at org.eclipse.jface.resource.LocalResourceManager.allocate(LocalResourceManager.java:82) at org.eclipse.jface.resource.AbstractResourceManager.create(AbstractResourceManager.java:88) at org.eclipse.jface.resource.ResourceManager.createImage(ResourceManager.java:172) at de.walware.eclipsecommons.ui.HandlerContributionItem.updateIcons(HandlerContributionItem.java:648) at de.walware.eclipsecommons.ui.HandlerContributionItem.fill(HandlerContributionItem.java:383) at org.eclipse.jface.action.SubContributionItem.fill(SubContributionItem.java:77) at org.eclipse.jface.action.ToolBarManager.update(ToolBarManager.java:349) at org.eclipse.ui.internal.ViewPane.updateActionBars(ViewPane.java:449) at org.eclipse.ui.internal.ViewActionBars.updateActionBars(ViewActionBars.java:59) at org.eclipse.ui.SubActionBars.updateActionBars(SubActionBars.java:610) at de.walware.statet.nico.ui.console.NIConsolePage$6.handleEvent(NIConsolePage.java:599) at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1158) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1182) at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1163) at org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:3284) at org.eclipse.swt.widgets.Control.gtk_event_after(Control.java:2684) at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1538) at org.eclipse.swt.widgets.Control.windowProc(Control.java:4506) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4099) at org.eclipse.swt.internal.gtk.OS._gtk_widget_grab_focus(Native Method) at org.eclipse.swt.internal.gtk.OS.gtk_widget_grab_focus(OS.java:9106) at org.eclipse.swt.widgets.Control.forceFocus(Control.java:2107) at org.eclipse.swt.widgets.Composite.forceFocus(Composite.java:494) at org.eclipse.swt.widgets.Control.forceFocus(Control.java:2101) at org.eclipse.swt.widgets.Control.setFocus(Control.java:3646) at org.eclipse.swt.widgets.Composite.setFocus(Composite.java:1254) at org.eclipse.swt.widgets.Composite.gtk_button_press_event(Composite.java:656) at org.eclipse.swt.widgets.Canvas.gtk_button_press_event(Canvas.java:155) at org.eclipse.swt.widgets.Widget.windowProc(Widget.java:1531) at org.eclipse.swt.widgets.Control.windowProc(Control.java:4506) at org.eclipse.swt.widgets.Display.windowProc(Display.java:4099) at org.eclipse.swt.internal.gtk.OS._gtk_main_do_event(Native Method) at org.eclipse.swt.internal.gtk.OS.gtk_main_do_event(OS.java:5792) at org.eclipse.swt.widgets.Display.eventProc(Displa
Re: [R] Eclipse and StatET Howto (also added Subversion, Rtools)
UPDATE on StatET and Ubuntu 8.10 amd64: StatET also works perfectly on Ubuntu 8.10 amd64, but the installation procedure takes a lot more effort than on XP Pro 32-bit or Vista 32-bit (at least from my experience). But I am very happy to have more RAM and having StatET working definitely helps the R-development experience. I also love the power of *nix, but like my experiences in the past, getting things to work right can be a big time-sink - it was the case with getting StatET working here. Some things to watch out for on Ubuntu 8.10 amd64 (you may or may not have the same issues): 1. Eclipse should be installed according to this procedure: http://flurdy.com/docs/eclipse/install.html You may get away with just setting ECLIPSE_HOME, but if you do nothing but unzip and run it, you may run into some weird run-time issues with StatET as described here: http://www.nabble.com/-SOLVED--Need-Help-with-StatET-Error-Bug--on-Ubuntu-8.10-amd64-td22905352.html 2. Follow my earlier post on this thread wrt rJava, -Drjava.path, and Sun JDK. Of course, there may be many different ways to get StatET working, but the steps in this thread worked for me. I posted these messages for others in appreciation of help that I got from other posted messages, but also for my future reference when I need to get StatET working on a newly-upgraded system. I hope someone finds this thread useful. - Ken -- View this message in context: http://www.nabble.com/Eclipse-and-StatET-Howto-%28also-added-Subversion%2C-Rtools%29-tp22764049p22907519.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] Need Help with StatET Error/Bug? on Ubuntu 8.10 amd64
Thank you, John, for this bit of information - it will be useful when I move to 64 bit Vista one of these days. FWIW, the Ubuntu 8.10 amd64 install I attempted was on 64-bit versions of everything (except possibly StatET itself). 64-bit R, JDK, and Eclipse. If someone does get StatET working on a 64-bit Windoze system, do please let us know. Thank you. - Ken John Fox-6 wrote: > > Dear Ken-JP, > > I'm not sure that this is relevant, but I posted a question recently to > the > StatET list about using StatET with 64 bit Vista (I don't yet have the > machine), and was told that it would work, but only with 32-bit versions > of > Eclipse and Java. > > I hope this helps, > John > -- View this message in context: http://www.nabble.com/-SOLVED--Need-Help-with-StatET-Error-Bug--on-Ubuntu-8.10-amd64-tp22905352p22908497.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 package: Where to put code to Run Once Only?
Is there a specific place where we can place code to run once only in a package? I have code that switches based on Sys.info()[["nodename"]] - but since this just about never changes, I would like to run it only once when someone runs: require( mypackage ) or library( vte ) I'm tempted to have some free-floating code in global space (in one of my package's .R files), but it just seems so wrong/hacky to do it this way. Where is the proper place to put this code? - Ken -- View this message in context: http://www.nabble.com/R-package%3A-Where-to-put-code-to-Run-Once-Only--tp22908592p22908592.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] R package: Where to put code to Run Once Only?
Thanks to pointers from Uwe, I first tried zzz.R and .First.lib(), which does what I needed (initialize once). Then under Martin's suggestion, I converted the package to use NAMESPACE and .onLoad(). Using NAMESPACE, I was able to hide my globals behind a "." (eg .myGlobal <<- 72) and use exportPattern("^[^\\.]*") to prevent users from seeing my globals, yet I was able to access their values inside my package. After a couple of hours of cleaning up, I was able to tighten my package to build cleanly (no warnings) for the first time in a long while with R CMD Check - on 3 different machines. I am happy to get no warnings on 2.8.1 (Ubuntu amd64) and 2.9 alpha (XP Pro 32 and Vista 32), where I learned something new about RDoc Version 2 (the difference between \description and \describe), changes going from 2.8.1 to 2.9. So with a little persistence and a lot of assitance from R-help I was able to tighten up the code and to build cleanly. Thank you. -- View this message in context: http://www.nabble.com/R-package%3A-Where-to-put-code-to-Run-Once-Only--tp22908592p22921596.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] parse_Rd() Version 2 on Japanese Vista 32 (encoding problems)
Hi, I need some help with 2.9.0 parse_Rd() Version 2 changes. I read the .pdf file and some posts on r-help, but after playing with this for several hours, I can't seem to get around this UTF-8 problem. - I'm trying to get rid of some warnings during R CMD Check for R 2.9.0Alpha on Japanese Vista 32 - The same setup on a R 2.9.0Alpha English XP Pro 32 works fine without any modification. - I just have ASCII text in my .Rd files. I don't need/intend to put any CJK characters in the files. Any ideas on how to eliminate the warnings would be greatly appreciated. - Ken --- Running R CMD Check: * checking Rd files against version 2 parser ... WARNING Warning in parse_Rd("./man/myfile.Rd", encoding = "unknown") : non-UTF-8 multibyte locales are not supported -- reencoding to UTF-8 *** error on file ./man/myfile.Rd Error in iconv(lines, enc, encoding, sub = "byte") : invalid 'from' argument --- So I tried to "cheat" by prepending: \encoding{UTF-8} at the top of myfile.Rd - this almost worked. The error went away, but now, I'm getting a flood of: Warning in grep("^[[:blank:]]*\n?$", x, perl = TRUE) : perl = TRUE is only fully implemented in UTF-8 locales -- View this message in context: http://www.nabble.com/parse_Rd%28%29-Version-2-on-Japanese-Vista-32-%28encoding-problems%29-tp22922309p22922309.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.