Re: [R] R code for overlapping variables -- count

2024-06-02 Thread Rui Barradas
À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(

Re: [R] R code for overlapping variables -- count

2024-06-02 Thread Rui Barradas
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í

Re: [R] Sorting strings

2012-02-20 Thread Rui Barradas
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

Re: [R] counting characters starting point

2012-02-20 Thread Rui Barradas
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

Re: [R] breaks display of hist

2012-02-21 Thread Rui Barradas
, ?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

Re: [R] removing particular row from matrix

2012-02-21 Thread Rui Barradas
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

Re: [R] counts

2012-02-22 Thread Rui Barradas
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

Re: [R] Table into a list

2012-02-24 Thread Rui Barradas
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

Re: [R] Dealing with NAs in C

2012-02-25 Thread Rui Barradas
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

Re: [R] count how many row i have in a txt file in a directory

2012-02-26 Thread Rui Barradas
... 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

Re: [R] count how many row i have in a txt file in a directory

2012-02-26 Thread Rui Barradas
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

Re: [R] compare two data frames of different dimensions and only keep unique rows

2012-02-27 Thread Rui Barradas
... 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

Re: [R] Principal Components for matrices with NA

2012-02-27 Thread Rui Barradas
(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

Re: [R] Principal Components for matrices with NA

2012-02-27 Thread Rui Barradas
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

Re: [R] compare two data frames of different dimensions and only keep unique rows

2012-02-27 Thread Rui Barradas
) #- # 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

Re: [R] from data.frame to Venn diagram

2012-02-27 Thread Rui Barradas
, 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

Re: [R] macro function

2012-02-28 Thread Rui Barradas
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

Re: [R] How to replace the values in a column

2012-02-29 Thread 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

Re: [R] function for filtering and deleting vector entries

2012-02-29 Thread Rui Barradas
- 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

Re: [R] identifying a column name correctly to use in a formula

2012-02-29 Thread Rui Barradas
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

Re: [R] 'break' function in loop

2012-03-01 Thread Rui Barradas
) } 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

Re: [R] select rows by criteria

2012-03-01 Thread Rui Barradas
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

Re: [R] select rows by criteria

2012-03-01 Thread Rui Barradas
== 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

Re: [R] select rows by criteria

2012-03-01 Thread Rui Barradas
. 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

Re: [R] read.table issue with #

2012-03-01 Thread Rui Barradas
' 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

Re: [R] subseting a data frame

2012-03-02 Thread Rui Barradas
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

Re: [R] Count matches in pmatch

2012-03-02 Thread Rui Barradas
(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

Re: [R] I want to fill a column in with 0 or 1 depending on another columns input

2012-03-05 Thread Rui Barradas
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

Re: [R] index instead of loop?

2012-03-05 Thread Rui Barradas
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

Re: [R] split array into groups by value

2012-03-05 Thread Rui Barradas
(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

Re: [R] index instead of loop?

2012-03-06 Thread Rui Barradas
, 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

Re: [R] index instead of loop?

2012-03-07 Thread Rui Barradas
, 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

Re: [R] , Exact Confidence Interval

2012-03-07 Thread Rui Barradas
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

Re: [R] index instead of loop?

2012-03-08 Thread Rui Barradas
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

Re: [R] Calling a column from a matrix using a variable

2012-03-08 Thread Rui Barradas
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

Re: [R] index values of one matrix to another of a different size

2012-03-09 Thread Rui Barradas
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

Re: [R] qmvnorm function

2012-03-14 Thread Rui Barradas
=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

Re: [R] qmvnorm function

2012-03-14 Thread Rui Barradas
] 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

Re: [R] Equation as a character string

2012-03-15 Thread Rui Barradas
)) (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

Re: [R] Accessing variable's name as an attribute?

2012-03-15 Thread Rui Barradas
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

Re: [R] Generation of correlated variables

2012-03-15 Thread Rui Barradas
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

Re: [R] Generation of correlated variables

2012-03-15 Thread Rui Barradas
] [,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

Re: [R] randomly subsample rows from subsets

2012-03-19 Thread Rui Barradas
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

Re: [R] Remove quotes from a string to use in a variable call

2012-03-20 Thread Rui Barradas
. 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

Re: [R] Remove individual rows from a matrix based upon a list

2012-03-20 Thread Rui Barradas
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

Re: [R] how to avoid grid overlapping in a boxplot

2012-03-22 Thread Rui Barradas
=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

Re: [R] How to compute within-group mean and sd?

2012-03-24 Thread Rui Barradas
) 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

Re: [R] copy the columns based on the code

2012-03-26 Thread Rui Barradas
(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

Re: [R] R extract parts

2012-03-27 Thread Rui Barradas
) - 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

Re: [R] scalar assignment within a vector within function

2012-03-29 Thread Rui Barradas
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

Re: [R] removing NA from multidmension arrays

2012-03-30 Thread Rui Barradas
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

Re: [R] avoiding expression evaluation when calling a function

2012-03-31 Thread Rui Barradas
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

Re: [R] clear console

2012-03-31 Thread Rui Barradas
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

Re: [R] Filling empty List in a FOR LOOP

2012-04-02 Thread Rui Barradas
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

Re: [R] Grouping and/or splitting

2012-04-03 Thread Rui Barradas
' 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

Re: [R] spaghetti plots in R

2012-04-04 Thread Rui Barradas
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

Re: [R] Selecting obs within groups defined by 2 variables

2012-04-04 Thread Rui Barradas
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

Re: [R] extract data

2012-04-04 Thread Rui Barradas
) 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

Re: [R] random sample from list

2012-04-05 Thread Rui Barradas
, 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

Re: [R] how to compute a vector of min values ?

2012-04-05 Thread Rui Barradas
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

Re: [R] filling the matrix row by row in the order from lower to larger elements

2012-04-07 Thread Rui Barradas
) 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

Re: [R] filling the matrix row by row in the order from lower to larger elements

2012-04-07 Thread Rui Barradas
))) (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

Re: [R] Order sapply

2012-04-07 Thread Rui Barradas
])) 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

Re: [R] Lagged values problem requiring short solution time

2011-12-12 Thread Rui Barradas
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

Re: [R] Lagged values problem requiring short solution time

2011-12-12 Thread 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

Re: [R] Problem with ploting fitted values

2011-12-13 Thread Rui Barradas
' 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

[R] htest class members and print method

2011-12-14 Thread Rui Barradas
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

[R] printing all htest class members

2011-12-15 Thread Rui Barradas
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

Re: [R] Data Manipulation - make diagonal matrix of each element of a matrix

2011-12-15 Thread Rui Barradas
, 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

Re: [R] printing all htest class members

2011-12-15 Thread Rui Barradas
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:

Re: [R] printing all htest class members

2011-12-15 Thread Rui Barradas
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

Re: [R] Help with code

2011-12-23 Thread Rui Barradas
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

Re: [R] Applying a function

2011-12-23 Thread Rui Barradas
/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

Re: [R] Applying a function

2011-12-23 Thread 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

Re: [R] if statement problem

2011-12-23 Thread Rui Barradas
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

Re: [R] Help creating a symmetric matrix?

2011-12-23 Thread Rui Barradas
(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

Re: [R] if statement problem

2011-12-25 Thread Rui Barradas
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

Re: [R] need help with a time series plotting problem

2011-12-25 Thread Rui Barradas
$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

Re: [R] [newbie] read row from file into vector

2011-12-29 Thread Rui Barradas
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

Re: [R] Conditionally adding a constant

2012-01-02 Thread Rui Barradas
(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

Re: [R] Conditionally adding a constant

2012-01-02 Thread Rui Barradas
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

Re: [R] problem on plotting ts data

2012-01-04 Thread Rui Barradas
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

Re: [R] Combining characters

2012-01-04 Thread Rui Barradas
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

Re: [R] automatic SI prefixes as ticklabels on axis

2012-01-05 Thread Rui Barradas
)) } 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

Re: [R] automatic SI prefixes as ticklabels on axis

2012-01-05 Thread Rui Barradas
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

Re: [R] automatic SI prefixes as ticklabels on axis

2012-01-06 Thread Rui Barradas
- 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

Re: [R] add data to a file while doing a loop

2012-01-06 Thread Rui Barradas
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

Re: [R] cbind alternate

2012-01-06 Thread Rui Barradas
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

Re: [R] cbind alternate

2012-01-06 Thread Rui Barradas
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

Re: [R] Convert components of a list to separate columns in a data frame or matrix XXXX

2012-01-08 Thread Rui Barradas
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-

Re: [R] Conditional Loop For Data Frame Columns

2012-01-09 Thread Rui Barradas
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

Re: [R] Conditional Loop For Data Frame Columns

2012-01-09 Thread 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

Re: [R] runif with condition

2012-01-09 Thread Rui Barradas
), 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

Re: [R] Averaging within a range of values

2012-01-13 Thread Rui Barradas
(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

Re: [R] Estimate the average abundance using Poisson regression with a log link.

2012-01-14 Thread Rui Barradas
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

Re: [R] Estimate the average abundance using Poisson regression with a log link.

2012-01-14 Thread Rui Barradas
. (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

Re: [R] Using Aggregate() with FUN arguments, which require more than one input variables

2012-01-17 Thread Rui Barradas
), 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

Re: [R] R package dev: how to export constant?

2012-01-17 Thread Rui Barradas
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

Re: [R] Split values in vector

2012-01-20 Thread Rui Barradas
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

Re: [R] Checking for invalid dates: Code works but needs improvement

2012-01-24 Thread Rui Barradas
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   2   3   4   5   6   7   8   9   10   >