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
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
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
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
-
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
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.
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:
# 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
# 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
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
# 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
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
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
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
# 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
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
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
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
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
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
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
21 matches
Mail list logo