Às 18:40 de 02/06/2024, Rui Barradas escreveu:
Às 18:34 de 02/06/2024, Leo Mada via R-help escreveu:
Dear Shadee,
If you have a data.frame with the following columns:
n = 100; # population size
x = data.frame(
Sex = sample(c("M","F"), n, T),
Country = sample(c(
mented, minimal, self-contained, reproducible code.
Hello,
The following is simpler.
r2 <- xtabs(~ ., x) |> as.data.frame()
r2[-4L] # or r2[names(r2) != "Freq"]
Hope this helps,
Rui Barradas
--
Este e-mail foi analisado pelo software antivírus AVG para verificar a presença
de ví
it be OS related?
Rui Barradas.
--
View this message in context:
http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4404267.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch
as.integer(pos - regexpr(chr, seq))
}
sapply(LETTERS, f, seq, chr)
}
rbind(
fun(seq1, ref1),
fun(seq2, ref2),
fun(seq3, ref3)
)
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/counting-characters
, ?par.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/breaks-display-of-hist-tp4406966p4407457.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https
Hello,
Try
a-matrix(c(1,2,3,4,4,5,6,6,-999.99,5,9,-999.00),nrow=4)
ix - apply(a, 1, function(x) sum(trunc(x) != -999) == ncol(a))
a[ix, ]
Hope this helps
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/removing-particular-row-from-matrix-tp4407401p4407490.html
Hello,
Just look at your second 'apply': the 'function(x)' is not using the 'x' (!)
Solution:
function(x) hist(x, breaks=0:nrow(test), plot=FALSE)$counts)
Note that instead of 'nrow' you could also use 'length(x)'.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r
Hello,
Try
(d - data.frame(x1=letters[2*1:4 - 1], x2=letters[2*1:4]))
c(apply(d, 1, identity))
Note that you'll need the concatenation 'c()'.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Table-into-a-list-tp4418804p4419091.html
Sent from
this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Dealing-with-NAs-in-C-tp4421377p4421439.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman
...
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/count-how-many-row-i-have-in-a-txt-file-in-a-directory-tp4422186p4422549.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r
Hello, again.
Did anyone ever mention the 'countLines' function in R.utils.
No, I didn't know about it.
Thanks.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/count-how-many-row-i-have-in-a-txt-file-in-a-directory-tp4422186p4423521.html
Sent from the R help
...
Anyway, I hope it gives ideas,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/compare-two-data-frames-of-different-dimensions-and-only-keep-unique-rows-tp4425379p4425605.html
Sent from the R help mailing list archive at Nabble.com
(length(x), 1)] - NA; x}
x - t(apply(x, 1, f))
x
x.without.NA - t(na.exclude(t(x)))
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Principal-Components-for-matrices-with-NA-tp4425930p4426040.html
Sent from the R help mailing list archive
Hello again,
Q: is there a way to do princomp or another method where every row has at
least one missing column?
See also package 'psych', function 'principal'. You can impute mean or
median to NAs.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Principal
)
#-
# And some other data types
x - 1:5
y - 3:8
x %-% y
y %-% x
symdiff(x, y)
symdiff(y, x)
X - list(a=x, rp=reported)
Y - list(b=y, ef=exportfile)
X %-% Y
Y %-% X
symdiff(X, Y)
symdiff(Y, X)
P.S. This question seems to pop-up repeatedly
Rui Barradas
--
View this message
,
cat.cex = 2.5,
cat.pos = 0
)
Error: Incorrect number of elements.
It seems to have a limit...
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/from-data-frame-to-Venn-diagram-tp4426642p4426853.html
Sent from the R help mailing list
2011-01-05
y - difftime(x[-1], x[1], units=days)
y - as.integer(y)
y
[1] 1 2 3 4
colNames[3] - D-Day
colNames[-(1:3)] - paste(D, y, sep=+)
colNames
[1] namepublish day D-Day D+1 D+2
[6] D+3 D+4
# colnames(DF) - colNames
Hope this helps,
Rui Barradas
]
DF$Gen[i] - TransTable[iTrans, 2]
}
# See first 6 lines of result
head(DF)
That's it.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-replace-the-values-in-a-column-tp4430448p4431983.html
Sent from the R help mailing list archive
- function(Temp, v){
unwanted - Temp = 16 | Temp = 38.5
Temp - Temp[!unwanted]
v - v[!unwanted]
list(Temp=Temp, v=v)
}
(tt - seq(10, 40, by=0.5))
(vv - 1:length(tt))
fun(tt, vv)
I've changed the name because 'norm' is a R function name. See ?norm
Hope this helps,
Rui
write the formula in full, using 'paste'.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/identifying-a-column-name-correctly-to-use-in-a-formula-tp4433605p4433924.html
Sent from the R help mailing list archive at Nabble.com
)
}
if(!is.null(results) nrow(results) == 5) break # Note 2
above
}
results1 - rbind(results1, results)
}
results
results1
Hope this helps
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/break-function-in-loop-tp4435033p4435151.html
Sent from the R help
to
compromise the two criteria.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/select-rows-by-criteria-tp4434812p4435257.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing
== min(meansDist2)))
to this
inxmat2 - with(DF, apply(inxmat, 2, function(x) setdiff(ID, x)))
meansDist2 - apply(inxmat2, 2, function(jnx) f(jnx, DF$value, 45))
(i2 - which(meansDist2 == min(meansDist2)))
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/select-rows
.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/select-rows-by-criteria-tp4434812p4435760.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman
' instead, followed by 'strsplit'.
In the example below the separator is a space.
tc - textConnection(
yes yes yes yes yes
yes yes yes yes yes
yes yes # yes yes
)
#x - read.table(tc) # same error: line 3 did not have 5 elements
x - readLines(tc)
close(tc)
strsplit(x, )
Hope this helps,
Rui
only the unique ones :(
Try
inx - match(unique(df$exon), df$exon)
df[inx, ]
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/subseting-a-data-frame-tp4438745p4438922.html
Sent from the R help mailing list archive at Nabble.com
(xmatch, list(xmatch), length)
by(xmatch, xmatch, length)
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Count-matches-in-pmatch-tp4439722p4440316.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r
vector
surg - x$Specialty == Surgery
# use it as integer, there are
# only two possibilities
x$Surgery - as.integer(surg)
x$Internal - as.integer(!surg)
x
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/I-want-to-fill-a-column-in-with-0-or-1-depending
timed it but I believe it should be faster.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/index-instead-of-loop-tp4447672p4448567.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help
(1,1,1,1, 0,0,0,0,0, 1,1,1,1,1,1)
contig - cumsum(abs(diff(c(x[1], x
split(x, contig)
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/split-array-into-groups-by-value-tp4448578p4448622.html
Sent from the R help mailing list archive at Nabble.com
, function(i)
which(x[i] = dt1 dt1 x[i + 1]))
sapply(1:length(ix), function(i)
if(length(ix[[i]])) fin1[ix[[i]], tkr + 1] - ua[i, tkr])
}
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/index-instead-of-loop
, 2012 at 8:22 AM, Rui Barradas lt;rui1174@gt; wrote:
Hello,
Just looking at this, but it looks like ix doesn't exist:
sapply(1:length(inxlist), function(i) if(length(ix[[i]]))
fin1[ix[[i]], tkr + 1] - ua[i, tkr])
Trying to sort it out now.
Right, sorry.
I've changed the name
commented, minimal, self-contained, reproducible code.
See package 'binom'. Function 'binom.confint' gives a choice of 8 different
methods,
Clopper-Pearson is the 'exact', and function 'binom.test' also uses it.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695
00.01 NANA
And the better news is that I believe it scales up without degrading
performance,
like my first did.
See if it works.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/index-instead-of-loop-tp4447672p4457290.html
Sent from the R
Hello,
Try
x-data.frame(A=1:5,B=6:10,C=11:15,D=16:20,E=21:26)
titles-c(A,B,C,E)
y - C
x[ , y]
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Calling-a-column-from-a-matrix-using-a-variable-tp4457466p4457509.html
Sent from the R help mailing
i2 - nr
for(j in 1:nc){
mat[i1:i2, 1] - inxdata[, j]
mat[i1:i2, 2] - rep(j, nr)
i1 - i1 + nr
i2 - i2 + nr
}
matrix(valdata[mat], ncol=nc)
}
fun(vals, indx)
Rui Barradas
--
View this message
=diag(5))$quantile
[1] -0.123829
From these results, there is nothing intrisically wrong with the quantile
0.05.
In the error message, 'uniroot' is not in an interval with a guaranteed
solution, maybe
the parameter 'interval' of 'qmvnorm' will put it in the right track.
Hope this helps,
Rui
] Normal Completion
$iter
[1] 9
$estim.prec
[1] 6.103516e-05
Your problem seems to be with, at least, 'uniroot'. Give it a help and it
might work.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/qmvnorm-function-tp4473262p4473638.html
Sent from the R help mailing list
))
(opt - optimize(g, interval=c(-300, 300)))
curve(g, from=-5, to=5)
points(opt$minimum, opt$objective, col='red')
This may be usefull if you don't know the function's analytic expression
beforehand.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com
C1 C2
1 C e 0.001311565 2.237548657
2 B d 1.393674594 0.507935464
3 C c -0.821700986 -2.118189680
4 C d 0.314210639 -0.771531899
[... etc ...]
99 C e -0.435389239 1.024320656
100 D e 0.919110919 0.667429797
Hope this helps,
Rui Barradas
--
View this message
Hello,
However, I would like that have all my regressors to be orthogonal (i.e.
no correlation among them.
?poly
poly(cbind(x1, x2, x3), degree=1)
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Generation-of-correlated-variables
] [,3]
[1,] 1.00e+00 2.804232e-17 -3.758236e-17
[2,] 2.804232e-17 1.00e+00 -1.492894e-17
[3,] -3.758236e-17 -1.492894e-17 1.00e+00
This works but I would use a Gram-Schmidt algorithm.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Generation
do.call(rbind, select)
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/randomly-subsample-rows-from-subsets-tp4483477p4483613.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r
. Thanks!
Try
response - distance
predictors - age + Sex
fmla.text - paste(response, predictors, sep=~)
update(fm2,fixed=as.formula(fmla.text))
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Remove-quotes-from-a-string-to-use-in-a-variable-call
produced with function 'dput', it makes it much,
much easier to create the objects.
See
?dput
and use it!
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Remove-individual-rows-from-a-matrix-based-upon-a-list-tp4489462p4490257.html
Sent from the R help
=FALSE)
grid()
boxplot(x, add=TRUE, col=white)
If you have two groups, the xlim would be c(0.5, 2.5), etc...
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-avoid-grid-overlapping-in-a-boxplot-tp4495955p4496688.html
Sent from the R help mailing
)
FROM tbl
GROUP BY firm_id;)
I've changed the name of your data.frame because 'table' is an R function.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/How-to-compute-within-group-mean-and-sd-tp4501504p4501709.html
Sent from the R help mailing list
(3, 2, 4, 1, 5)]
The general idea is obvious, I believe: you want to relate 'cod/city' from
table 'city' with
two columns of table 'travel', one is source and the other is destine. So
you need to merge the tables twice.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r
) - NULL
result
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/R-extract-parts-tp4509042p4510566.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https
assignments but don't do this
test[i] - r2
without readind P. Burns, The R Inferno, Circle 6.
http://www.burns-stat.com/pages/Tutor/R_inferno.pdf
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/scalar-assignment-within-a-vector-within-function
this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/removing-NA-from-multidmension-arrays-tp4519369p4519750.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https
in a strange way.
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/avoiding-expression-evaluation-when-calling-a-function-tp4520151p4520876.html
Sent from the R help mailing list archive at Nabble.com.
__
R
Hello,
Try
cls2 - function(lines=25) cat(rep(\n, lines))
cls2()
It's simpler, and doesn't need any special package.
(In my system, R 2.14.1/Windows 7, i386 or x64, '\f' didn't work.)
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/clear
example of your data.
Clear enough?
Rui Barradas.
--
View this message in context:
http://r.789695.n4.nabble.com/Filling-empty-List-in-a-FOR-LOOP-tp4522694p4524695.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org
' defaults to FALSE. Was that the problem?
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Grouping-and-or-splitting-tp4530410p4530624.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help
244.3871 350.1785 454.6706 546.5499 638.3344
741.9849 842.5700 953.9648 995.8201
10.34615 52.02754 146.4656 244.9480 351.5865 457.1768 550.1341 643.0880
748.1114 850.0670 951.6384 987.9105
))
matplot(t(ak), t(pre), type=l)
Note that t() was needed.
Hope this helps,
Rui Barradas
--
View this message
1 y 2
2 x 1
2 x 2
2 y 1
2 y 2
, header=TRUE)
last -by(mydata, list(mydata$C1, mydata$C2), tail, n=1)
last
# Another way, output is more usefull.
last2 - aggregate(mydata, list(mydata$C1, mydata$C2), tail, n=1)
last2[, -(1:2)]
Hope this helps,
Rui Barradas
--
View this message in context
)
f.runs(x, 2)
f.runs(x, 3)
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/extract-data-tp4533176p4533288.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https
, create some fake data.
n - 1000
z - list()
set.seed(1234)
for(i in 1:n) z[[i]] - sample(letters, 2)
# Now sample some unique elements from it.
iz - which(!duplicated(z))
iz - sample(iz, 100) # sample from the non-duplicate indices.
z[iz]
Hope this helps,
Rui Barradas
--
View this message
Hello,
Try
apply(df, 2, min)
(By the way, 'df' is the name of a R function, avoid it, 'DF' is better.)
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/how-to-compute-a-vector-of-min-values-tp4536224p4536275.html
Sent from the R help mailing list
)
all.equal(f(input), desired.result)
# Two other examples
set.seed(123)
(x - matrix(sample(10, 10), ncol=2))
f(x)
(y - matrix(sample(40, 40), ncol=5))
f(y)
Note that there's no loops (or apply, which is also a loop.)
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com
)))
(desired.result)
all.equal(f(input), desired.result)
# Two other examples
set.seed(123)
(x - matrix(sample(10, 10), ncol=2))
f(x)
(y - matrix(sample(40, 40), ncol=5))
f(y)
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/filling-the-matrix-row
]))
You can also use Sarah's suggestion and have the entire results data frame
ordered
inx_ord - with(results_user, order(user, v_source, v_destine))
results_user[inx_ord, ]
Hope this helps,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Order-sapply-tp4537496p4539748
Kevin,
I'm sorry, but my code has a bug
The correction is:
1) delete the two lines with 'ix'
2) replace them with
for(i in 2:n)
if(abs(x[i] - x[i-1]) delta) x[i] - x[i-1] + delta
That's it. The problem is that it's back to slowness.
Sorry, once again,
Rui Barradas
- system.time(for(i in 1:10^2) y2 - fun2(x, delta=0.75))[c(1, 3)]
rbind(fun1=t1, fun2=t2, ratio=t1/t2)
#
# Sample run
#
user.self elapsed
fun1 26.99000 29.6
fun20.92000 1.09000
ratio 29.33696 27.15596
29 times faster!
I hope it's usefull
Rui Barradas
--
View this message
' and
see if it
solves the problem. R does allow this use but it conflicts with normal
functioning.
Rui Barradas.
--
View this message in context:
http://r.789695.n4.nabble.com/Problem-with-ploting-fitted-values-tp4192218p4193464.html
Sent from the R help mailing list archive at Nabble.com
it?
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/htest-class-members-and-print-method-tp4196932p4196932.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch
is NOT the return values, at least the time wasn't wasted,
I can use them for whatever I'll do next.
If not, anyone has any suggestions?
Thank you in advance,
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/printing-all-htest-class-members-tp4200872p4200872.html
Sent from the R
, it's not a great speed improvement.
I hope it's at least usefull.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Data-Manipulation-make-diagonal-matrix-of-each-element-of-a-matrix-tp4200321p4201305.html
Sent from the R help mailing list archive at Nabble.com
You're right, David,
The first line is wrong, it should be
... df=2:4 ...
As for creating something, try
ht - structure( ... etc ...
ht
class(ht)
See what is printed and what function prints it.
Rui
--
View this message in context:
Hello,
Once again, and as simple as possible,
res - data.frame(ord=2:4, df=2:4, Q=c(0.0129, 0.049, 0.0684),
p=c(0.9936, 0.9972, 0.9994))
ht2-structure(
list(statistic=c(Q=res$Q[1]),
p.value=res$p[1],
parameter=c(df=res$df[1]),
alternative=It
if(stype == Ctrl) c2_row[j] - Ctrl_noc
}
}
c2 - rbind(c2, c(c2_row, ptype))
}
c2 - data.frame(c2)
colnames(c2) - colnames(c1)
c2
I bet there's a way to work on entire objects. This is C-like.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Help
/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Hello,
Here is a one line function
recovery.rate - function(x) unlist(lapply(split(tab1, tab1[,2]),
function(x) mean(x[[4]]==y)))
It works with that table. I hope it helps
Merry Christmas
Rui Barradas
Sorry, in the function body, NO 'tab1', use 'x' only:
recovery.rate - function(x) unlist(lapply(split(x, x[,2]), function(x)
mean(x[[4]]==y)))
The error is because 'tab1' existed in the environment and the function
would find it.
This time, tested after removing 'tab1'.
Rui Barradas
--
View
properly.
x = cbind(obs1,obs2,exp1,exp2)
a = matrix(c(0,0,0,0), ncol=2, byrow =TRUE)#matrix with
initialized values
for (i in 1: length(x[,1]))
{
*if((x[i,1] || x[i,2] || x[i,3] || x[i,4]) 5)*
Hello,
Try
*if(any(x[i,] 5))*
Merry Christmas
Rui Barradas
--
View
(6)
ind - lower.tri(z)
z[ind] - v#This works
z
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Help-creating-a-symmetric-matrix-tp4227301p4230335.html
Sent from the R help mailing list archive at Nabble.com
the 'if'?
Then, you could simply test if any 'a' is less than 5.
for (i in 1: row(x))
{
a[1,1] - x[i,1];
a[1,2] - x[i,2];
a[2,1] - x[i,3];
a[2,2] - x[i,4];
if(any(a 5))
{
etc...
(Or use the compound '|' ).
Rui
$USGS700) # just the first series, ugly axes
If this helps, then make it pretty with Jim's ideas.
See also the 'plot.zoo' help page, it has several examples with fancy
labels.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/need-help-with-a-time-series-plotting
line it's fast, if you have a large file, cycle through.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/newbie-read-row-from-file-into-vector-tp4243952p4244038.html
Sent from the R help mailing list archive at Nabble.com
(10,20,30,NA,NA))
apply(df, 2, f1) # df$x[4] 3, df$x[5] also changes
apply(df, 2, f2) # only df$y has NA's
Maybe there's a better way, avoiding the loop.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Conditionally-adding-a-constant-tp4253049p4253125.html
0.01000 0.01000
t2.t3 13.31818 13.40909
t2.t4 293.0 295.0
t3.t4 22.0 22.0
A factor of 300 over the initial solution or 20+ over the other loop based
one.
Downside, it needs an extra package loaded, but 'zoo' is rather common
place.
Rui Barradas
--
View this message
Hello,
Try 'as.vector' or 'as.numeric'
x - as.ts(rnorm(20))
y - as.ts(rnorm(20))
plot(x)
plot(as.vector(lag(x,-9)),as.vector(y),type=p) # works
plot(as.numeric(lag(x,-9)),as.numeric(y),type=p) # also works
Rui Barradas
--
View this message in context:
http://r.789695.n4
it into a
function and use the function:
f - function(x, y) unlist(lapply(x, function(x) paste(x,y)))
f(x, f(y, z))
With more than 3 vectors, you could try a recursive version.
I hope this helps.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Combining-characters
))
}
getSIstring2(2e7)
getSIstring2(2e-8)
getSIstring2(c(2e7, 2e-8))
getSIstring2(c(2e7, 2e-8, 1234))
I've included the value 1234 because I coudn't understand wether it could be
passed to the function.
To return '1 k', use a 'round' inside the paste to round the division value.
See ?round
Rui
I forgot to say I have commented out your function's first line,
sistring - paste(x)
It wouldn't cause any problem, it's just not needed.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/automatic-SI-prefixes-as-ticklabels-on-axis-tp4266141p4267965.html
Sent from
- paste(x/lut[ix], pre[ix]),
sistring - as.character(x))
sistring[which(sistring == Inf Y)] - Inf # make it look better
return(sistring)
}
getSIstring(c(4.2e-3, 2e7))
x1 - .Machine$double.xmax
x2 - x1 + 10^(308 - 16)
getSIstring(c(x1, x2))
Rui Barradas
--
View
Hello,
See
?open and ?capture.output
or
?textConnection
To open a connection (with 'open') then write to it is probably the
solution.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/add-data-to-a-file-while-doing-a-loop-tp4269086p4269396.html
Sent from the R
and
character.
If you also need the matrix, try to use 'cbind' first, without writing to a
file.
If it's still slow, adapt the code above to keep inserting chunks in an
output matrix.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/cbind-alternate-tp4270188p4270444
1.640.121.76
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/cbind-alternate-tp4270188p4270687.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.ch
list2 - list(x=1:3, y=1:5, z=abc)
fun(list2)
The function returns a list, then it can be made a matrix, a data.frame or
whatever.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Convert-components-of-a-list-to-separate-columns-in-a-data-frame-or-matrix-
Hello,
I believe that the following solves it:
aggregate(SD[, 3:ncol(SD)], by=list(ID), mean)
aggregate(SD[, 3:ncol(SD)], by=list(ID), mean, na.rm=TRUE)
It's the second you want, it will compute the means for groups that aren't
only NA
and return NaN for groups with all values NA.
Rui Barradas
))
user system elapsed
3.210.033.24
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Conditional-Loop-For-Data-Frame-Columns-tp4276821p4280873.html
Sent from the R help mailing list archive at Nabble.com.
__
R
),
or a discrete distribution, rdisc(3)).
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/runif-with-condition-tp4278704p4281103.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https
(without a loop).
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Averaging-within-a-range-of-values-tp4291958p4294017.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https
P.S.
I don't understand what you mean by log link but if it's the use of a
log-normal to get improved confidence intervals, package 'SPECIES'
implements it, unlike 'Rcapture' that only gives point estimates.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com
. (The poisson model is a natural one).
3. Personally, I prefer the first, but this is because I'm more used to it
and have never worked with 'SPECIES', just took a look at it.
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/Estimate-the-average-abundance-using-Poisson
),
stringsAsFactors=FALSE)
# And test it. Note the argument 'stringsAsFactors'
cor.groups(DF, U)
cor.groups(DF, c(U, V))
cor.groups(DF, 1:3)
cor.groups(DF, c(U, x)) # look out, right result, wrong function
call
I hope it helps. (if not, be more explicit)
Rui Barradas
--
View this message
parameter's name has changed...)
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com/R-package-dev-how-to-export-constant-tp4305281p4305569.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org
0 0 0 12
5 E NANANANA
)
wanted - read.table(tc, header=TRUE)
close(tc)
(res1 - fun(x, var3))
(res2 - fun(x, 3))
all.equal(wanted, res1)
all.equal(wanted, res2)
Rui Barradas
--
View this message in context:
http://r.789695.n4.nabble.com
Hello,
Point 3 is very simple, instead of 'print' use 'cat'.
Unlike 'print' it allows for several arguments and (very) simple formating.
{ cat(Error: Invalid date values in, DateNames[[i]], \n,
TestDates[DateNames][[i]][TestDates$Invalid==1], \n) }
Rui Barradas
--
View
1 - 100 of 2931 matches
Mail list logo