[R] tcltk table properties

2015-10-01 Thread Dan D
I have a tkwidget table (say, tbl1) that may be reconfigured at various times depending on user input. Is there an easy way to later extract table properties? Something like... nrow<-tkgetproperties(tbl1, rows) Muchas thanks in advance. -Dan -- View this message in context: http://r.789695.n

[R] vector manipulations -- differences

2015-09-21 Thread Dan D
I need an efficient way to build a new n x (n-1)/2 vector from an n-vector x as: c(x[-1]-x[1], x[-(1:2)]-x[2], ... , x[-(1:(n-1)] - x[n-1]) x is increasing with x[1] = 0. The following works but is not the greatest: junk<-outer(x, x, '-') junk[junk>0] e.g., given x<-c(0, 3, 7, 20) junk<-outer

Re: [R] c(1:n, 1:(n-1), 1:(n-2), ... , 1)

2015-09-17 Thread Dan D
Very nice variety of solutions to create c(1:n, 1:(n-1), 1:(n-2), ... , 1) #Testing the methods with n=1000 (microbenchmark) n<-1000 # by far the nicest-looking, easiest to follow, and fastest is Frank Schwidom's: # it also requires the minimum amount of memory (as do several of the others) # 2.7

[R] c(1:n, 1:(n-1), 1:(n-2), ... , 1)

2015-09-17 Thread Dan D
Can anyone think of a slick way to create an array that looks like c(1:n, 1:(n-1), 1:(n-2), ... , 1)? The following works, but it's inefficient and a little hard to follow: n<-5 junk<-array(1:n,dim=c(n,n)) junk[((lower.tri(t(junk),diag=T)))[n:1,]] Any help would be greatly appreciated! -Dan -

Re: [R] Help with vectors!

2015-09-09 Thread Dan D
VAS<-c("Green","Green","Black","Green","White","Yellow","Yellow","Black","Green","Black") c(factor(VAS)) # to give integer indexing to the colors --- This is very nice, Frank. And it can be easily adjusted to match the original criterion that the numbers match the order of appearance of the colors

Re: [R] Help with vectors!

2015-09-08 Thread Dan D
Great! -- View this message in context: http://r.789695.n4.nabble.com/Help-with-vectors-tp4711801p4712023.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.

Re: [R] Counting number of rain

2015-09-08 Thread Dan D
Try the following: ## step 1: write raw data to an array junk<-scan('clipboard') # entering the numbers (not the 'year' etc. labels) into R as a vector after junk<-t(array(junk,dim=c(4,length(junk)/4))) # convert the vector into a 2-d array with 4 columns (year, month, day, amount) ## step 2:

Re: [R] extracting every nth character from a string...

2015-09-07 Thread Dan D
# as a complete function StrSubset<-function(junk,n){ ifelse(n==1,junk, paste(strsplit(junk,split=NULL)[[1]][(1:nchar(junk))%%n==1],collapse='')) } -- View this message in context: http://r.789695.n4.nabble.com/extracting-every-nth-character-from-a-string-tp4711908p4711963.html Sent from th

Re: [R] extracting every nth character from a string...

2015-09-07 Thread Dan D
# or: strsplit("junk",split=NULL)[[1]][(1:nchar("junk"))%%2==1] strsplit("junk",split=NULL)[[1]][(1:nchar("junk"))%%2==0] -- View this message in context: http://r.789695.n4.nabble.com/extracting-every-nth-character-from-a-string-tp4711908p4711962.html Sent from the R help mailing list archiv

Re: [R] Help

2015-09-07 Thread Dan D
press ESC. You may have entered a command that was missing a parenthesis or something else that R needs before it can make sense out of your code (e.g., entering "sum(X" without the closing paren will give you that pattern). ESC brings back the command line and you can try again. -Dan -- View

Re: [R] Handling "NA" in summation

2015-09-06 Thread Dan D
# it's not clear what your question is, but here's a stab in the dark at a solution! ind<- !is.na(dataframe$A) & !is.na(dataframe$B) dataframe$A[ind] + dataframe$B[ind] - Dan P.S. I'm sure there are ways to do this using one of R's functions for automatically removing NA's (na.rm = T), but unle

Re: [R] [Bayesian Methods] Riemann Sums for Posterior expected loss

2015-09-05 Thread Dan D
Does this get you started? f<-function(t,cx){ (abs(t-cx)*(t >= cx)+10*abs(t-cx)*(t < cx))*dbeta(t,1.05,30) } integrate(f,lower=0,upper=1,cx=0.4)$val # e.g., for c = 0.4 The "integrate" function integrates over the first parameter. Other parameters can be entered as needed. [Note: I used cx as

Re: [R] Plots Help

2015-09-05 Thread Dan D
length(post) is 1 (i.e., it is just a single function), but length(post(t)) == length(t) -- View this message in context: http://r.789695.n4.nabble.com/Plots-Help-tp4711894p4711897.html Sent from the R help mailing list archive at Nabble.com. __ R-he

Re: [R] Plots Help

2015-09-05 Thread Dan D
As written, the code does not run because you are trying to plot post vs. t. Try instead: plot(t, post(t)), or, more simply, plot(t, dbeta(t,1.05,30)) -Dan -- View this message in context: http://r.789695.n4.nabble.com/Plots-Help-tp4711894p4711896.html Sent from the R help mailing list archive

Re: [R] Help with vectors!

2015-09-05 Thread Dan D
# your data VAS<-c("Green","Green","Black","Green","White","Yellow","Yellow","Black","Green","Black") # declare the new vector New_Vector<-numeric(length(VAS)) # brute force: New_Vector[VAS=="White"]<-1 New_Vector[VAS=="Yellow"]<-2 New_Vector[VAS=="Green"]<-3 New_Vector[VAS=="Black"]<-4 # a litt

Re: [R] For Loops please help!!

2015-09-05 Thread Dan D
Yes, the cause is memory use patterns, but the price is steep nonetheless. E.g.: rate<-log(400*1.1^(1:30)) # runs about 27x times as fast as the following (test via 'microbenchmark') rate<-numeric(30) for (i in 1:30){ rate[i]<-log(400*1.1^i) } When manipulating large arrays, the difference

Re: [R] For Loops please help!!

2015-09-05 Thread Dan D
Also, any time you write "for" in R, you pay a steep price in performance. In a short, simple loop it may not be noticeable, but in a more challenging problem it can be a huge issue. A more efficient way to write your loop would be: infectrate = 400*1.1^(1:30) # calculation cbind(1:30,log(infectra

Re: [R] For Loops please help!!

2015-09-05 Thread Dan D
The code has an error so it won't run as written. Instead of: infectrate[n]= (400)(1.1)^(n); try: infectrate[n]= 400*1.1^n; What I get after making this change looks right. -- View this message in context: http://r.789695.n4.nabble.com/For-Loops-please-help-tp4711882p4711884.html Sent from

Re: [R] Gamma count

2015-09-04 Thread Dan D
Pick the mean (mu) and variance (sig2) you want. Then, shape = mu^2/sig2 and scale = sig2/mu. This should work fine if your mean is large enough so that p(x = 0 or 1) is small. -- View this message in context: http://r.789695.n4.nabble.com/Gamma-count-tp4711845p4711853.html Sent from the R help

[R] edit GUI preferences for current session?

2015-09-03 Thread Dan D
I'd like to edit the GUI preferences for the current (Windows) session via command line rather than the Edit|GUI preferences menu. In particular, is there a way to change the pagerstyle to singlewindow without using the menu or editing the RConsole file? Any ideas? Thanks! -Dan -- View this m

[R] file.show cleanup

2015-09-03 Thread Dan D
The file.show() function seems to be exactly what I'm needing for displaying file contents for users, but I need something like "file.close()" to close the "R Information" window to clean up afterwards. Does anyone know if there is such a thing? -Dan -- View this message in context: http://r.7