Re: [R] Working with necessary columns in R (CSV)

2010-11-17 Thread Petr Savicky
the function strsplit(). Petr Savicky. __ 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

Re: [R] how to apply sample function to each row of a data frame?

2010-11-19 Thread Petr Savicky
On Fri, Nov 19, 2010 at 10:34:26AM -0800, wangwallace wrote: this is a simple question, but I wasn't able to figure it out myself. here is the data frame: M P Q 1 2 3 4 5 6 7 8 9 M, P, Q each represent a variable I want to draw 2 random sample from each row separately to create

Re: [R] how to apply sample function to each row of a data frame?

2010-11-20 Thread Petr Savicky
On Fri, Nov 19, 2010 at 07:22:57PM -0800, wangwallace wrote: actually, what I meant is to draw two random numbers from each row separately to create a new data frame. for example, an example output could be: 1 3 4 5 9 8 This may be done, for example X - matrix(1:9, ncol = 3, byrow =

Re: [R] [beginner] simple keyword to exit script ?

2010-11-21 Thread Petr Savicky
On Sun, Nov 21, 2010 at 10:56:14AM -0500, David Winsemius wrote: On Nov 21, 2010, at 10:43 AM, madr wrote: Is there any way of suppressing that error, like in other programming languages you can specifically invoke an error or simply exit, If you are in a function, then return() like

Re: [R] how to apply sample function to each row of a data frame?

2010-11-22 Thread Petr Savicky
(A), ncol=3) for (i in seq(nrow(A))) { C[i, 1] - A[i, ind[i, 1]] C[i, 2:3] - A[i, 3 + ind[i, 2:3]] } Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http

Re: [R] options()$width does not equal actual console width - why?

2010-11-26 Thread Petr Savicky
independently on the actual console size. The help page ?options says Some R consoles automatically change the value when they are resized. In order to get the actual console size under Linux, one can use Sys.getenv(COLUMNS). I do not know, whether this applies also to MasOS. Petr Savicky

Re: [R] unexpected behavior using round to 2 digits on randomly generated numbers

2010-11-29 Thread Petr Savicky
in some situations, may be found in the first section of http://rwiki.sciviews.org/doku.php?id=misc:r_accuracy and in http://rwiki.sciviews.org/doku.php?id=misc:r_accuracy:decimal_numbers Petr Savicky. __ R-help@r-project.org mailing list https

Re: [R] modification of cross-validations in rpart

2011-07-05 Thread Petr Savicky
a comprehensible model. Hope this helps. Petr Savicky. __ 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

Re: [R] Naive Bayes Classifier

2011-07-08 Thread Petr Savicky
attributes are treated in function CoreModel(y ~ ., lrn, model=bayes) in package CORElearn. I assume that the binomial distribution is used also in other implementations of naive Bayes for binary data. Petr Savicky. __ R-help@r-project.org mailing list https

Re: [R] cluster by unique value

2011-07-18 Thread Petr Savicky
3 9 0.2 2 1 1 100.8 2 4 6 Hope this helps. Petr Savicky. __ 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

Re: [R] Question on RNG

2011-08-06 Thread Petr Savicky
details, in particular in the initialization algorithm. In order to obtain the same stream of numbers, it will be needed either to copy the initialization algorithm from R to the C# implementation or vice versa. I can provide more detail off-list, if you are interested. Petr Savicky

Re: [R] Question on RNG

2011-08-07 Thread Petr Savicky
On Sat, Aug 06, 2011 at 09:37:22PM +0200, Petr Savicky wrote: On Fri, Aug 05, 2011 at 11:47:49PM +0530, Ron Michael wrote: Hi all, I have happened to work on MS .NET for sometime now, and I found that this language offers RNG what is called as Donald E. Knuth's subtractive random number

Re: [R] Counting

2011-03-17 Thread Petr Savicky
explain it in more detail? I would expect ave(u, a[, 2], FUN=sum) [1] 3 1 1 3 3 2 2 However, this is different from your expected output. Do you count only consecutive equal elements? Hope this helps. Petr Savicky. __ R-help@r-project.org mailing

Re: [R] subset data frame with condition

2011-03-18 Thread Petr Savicky
(1,1,1,1,1,2,2,2,2,3,3,3,4,4)) final - rep(FALSE, times=nrow(pop)) for (k in 1:3) { is.k - pop$Area == k accept - is.k (cumsum(is.k) = ceiling(sum(is.k)/2)) final - final | accept } pop[final, , drop=FALSE] # drop= not needed, if there are more columns Hope this helps. Petr Savicky

Re: [R] subset data frame with condition

2011-03-18 Thread Petr Savicky
this helps. Petr Savicky. __ 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] BFGS and Neldear-Mead

2011-03-18 Thread Petr Savicky
methods may found different ones. Can you send more detail about the minimized function? Petr Savicky. __ 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

Re: [R] How would you avoid loops in this simple example?

2011-03-19 Thread Petr Savicky
. Petr Savicky. __ 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] Number of edges in a graph

2011-03-21 Thread Petr Savicky
g, which can then be used to extract only some of them. Hope this helps. Petr Savicky. __ 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

Re: [R] Replacing Period in String

2011-03-21 Thread Petr Savicky
] This is a test However, it is only a test Petr Savicky. __ 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

Re: [R] Combination that adds a value

2011-03-21 Thread Petr Savicky
this helps. Petr Savicky. __ 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] Basic Looping Trouble

2011-03-22 Thread Petr Savicky
) var3 - seq(0, 1, length=11) for (varnam in c(var1, var2, var3)) { x - get(varnam) print(mean(x)) } Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read

Re: [R] round number

2011-03-26 Thread Petr Savicky
noquote(formatC(a*0.2, digits=2, format=f)) [1] 0.80 The two-digit form 0.80 is used also if a vector is printed and some other component requires 2 digits. For example c(a*0.2, 0.01) [1] 0.80 0.01 Hope this helps. Petr Savicky. __ R-help@r

Re: [R] export data to gnuplot

2011-03-27 Thread Petr Savicky
not using gnuplot for a long time, but i think a space delimited file can be used. Hope this helps. Petr Savicky. __ 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

Re: [R] matrix inverstion

2011-03-29 Thread Petr Savicky
determinant is an integer, it has to be zero and the difference from zero is due to rounding error. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R

Re: [R] Creating 3 vectors that sum to 1

2011-03-29 Thread Petr Savicky
will be exactly all ones vector. Otherwise, there may be differences within machine rounding error. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R

Re: [R] Simple but elusive - expand back from counts

2011-03-29 Thread Petr Savicky
row.names(tmp1) - NULL tmp1 V1 V2 V3 V4 1 44 10 abc 1 2 44 10 def 1 3 44 12 abc 1 4 44 12 abc 1 Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide

Re: [R] Creating 3 vectors that sum to 1

2011-03-30 Thread Petr Savicky
) and (2) together is about 27 times larger than (1) alone. (The ratio converges to 27, if A is limited to small neighborhood of the center). Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read

Re: [R] uniroot speed and vectorization?

2011-04-02 Thread Petr Savicky
, a))) It can be more efficient to find approximations of the roots using a few iterations of the above approach and then switch to the Newton method, which can be vectorized easily. Hope this helps for a start. Petr Savicky. __ R-help@r-project.org mailing list

Re: [R] Support Counting

2011-04-04 Thread Petr Savicky
) rowSums(db[, itemset]) == length(itemset) [1] TRUE TRUE FALSE FALSE TRUE # the number of transactions containing c(A, B) sum(rowSums(db[, itemset]) == length(itemset)) [1] 3 Hope this helps. Petr Savicky. __ R-help@r-project.org mailing

Re: [R] Search arrays based on similar values

2011-04-06 Thread Petr Savicky
. The first column of B seems to contain consecutive integers 1:nrow(B). If this is true, then try following B - cbind(1:6, c(0.1, 0.3, 0.14, 0.2, 0.82, 0.21)) A - rbind(1, 1, 1, 2, 3, 3, 4, 6) cbind(B[A[, 1], 2]) Hope this helps. Petr Savicky. __ R

Re: [R] Support Counting

2011-04-06 Thread Petr Savicky
) avec[indices] - 1 amat - rbind(avec) or amat - matrix(0, nrow=1, ncol=14) amat[1, indices] - 1 amat [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] avec001011000 1 0 0 0 0 Hope this helps. Petr

Re: [R] Decimal Accuracy Loss?

2011-04-06 Thread Petr Savicky
of s - s + x[i] in double precision. Petr Savicky. __ 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

Re: [R] Question about levels/as.numeric

2011-04-10 Thread Petr Savicky
7444 2244 5149 787 1717 5251 4122 3878 1811 These are indices to the levels of the factor. Petr Savicky. __ 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

Re: [R] Question about levels/as.numeric

2011-04-11 Thread Petr Savicky
the following which(is.na(as.numeric(as.character(returns[, 1] This will show the indices of the rows, which cannot be converted to numeric type. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] Password-protect R script files

2011-04-11 Thread Petr Savicky
works , A possible approach is to put the script into an extension package. This does not prevent the user to modify the script, but makes it almost impossible to change it inadvertently. Petr Savicky. __ R-help@r-project.org mailing list https

Re: [R] Coding matrix equation

2011-04-11 Thread Petr Savicky
. The package mvtnorm http://cran.at.r-project.org/web/packages/mvtnorm/index.html computes the square root of a matrix internally. See the help of the function ?rmvnorm. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https

Re: [R] Comparison of the amount of computation

2011-04-14 Thread Petr Savicky
In this case, mean(sample(100, 100, replace=TRUE)) and mean(unique(sample(100, 100, replace=TRUE))) have the same expected value 50.5. However, eliminating repeated values may, in general, change the expected value of the sample mean. Hope this helps. Petr Savicky

Re: [R] Comparison of the amount of computation

2011-04-14 Thread Petr Savicky
On Thu, Apr 14, 2011 at 12:40:53AM -0700, helin_susam wrote: Hi Petr, Your idea looks like logically. So, can we say this with your idea; the expected number of computation in unique(sample(...)) is fewer than sample(...). Because, the expected length is 63.39677 in unique case, while the

Re: [R] coercion

2011-04-20 Thread Petr Savicky
a reproducible example, you have a better chance to get a useful answer. Petr Savicky. __ 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

Re: [R] Fibonacci

2011-04-20 Thread Petr Savicky
) - 1] + Fibonacci[length(Fibonacci)]) } Petr Savicky. __ 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

Re: [R] Help with matching rows

2011-04-21 Thread Petr Savicky
Hope this helps. Petr Savicky. __ 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

Re: [R] all combinations with replacement

2011-04-21 Thread Petr Savicky
choose(n + k - 1, k - 1) among n^(k - 1) rows and not among n^k. Hope this helps. Petr Savicky. __ 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

Re: [R] Matching a vector with a matrix row

2011-04-24 Thread Petr Savicky
be done by comparing integers instead of character values, which is faster. Hope this helps. Petr Savicky. __ 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

Re: [R] set.seed( ) function

2011-04-24 Thread Petr Savicky
starting points. Petr Savicky. __ 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] Random Normal Variable Correlated to an Existing Binomial Variable

2011-04-25 Thread Petr Savicky
of the distribution (f(Y), Y) and (X, Y), where X has the required marginal distribution of X, but is generated independently from Y. The mixture parameter may be determined as a solution of an equation with one variable. Hope this helps. Petr Savicky. __ R-help

Re: [R] blank space escape sequence in R?

2011-04-25 Thread Petr Savicky
+0066 LATIN SMALL LETTER Ff Hope this helps. Petr Savicky. __ 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

Re: [R] Factor function

2011-04-25 Thread Petr Savicky
: xx yy Hope this helps. Petr Savicky. __ 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

Re: [R] Factor function

2011-04-26 Thread Petr Savicky
NA Levels: xx yy If the replacement should be done in the whole matrix, then a[a==NA]-NA may be used. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R

Re: [R] matrix of higher order differences

2011-04-27 Thread Petr Savicky
, the first row becomes the main diagonal. The initial part of each of the remaining rows becomes a diagonal starting at the first component of the original row. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE

Re: [R] How to define specially nested functions

2011-04-28 Thread Petr Savicky
)$root [1] 5 Hope this helps. Petr Savicky. __ 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

Re: [R] threshold matrix

2011-04-29 Thread Petr Savicky
) for approximate equality of all entries. See also ?all.equal, which uses the relative error, not absolute difference. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting

Re: [R] Sorting dataframe by number of occurrences of factor

2011-04-30 Thread Petr Savicky
), ] Hope this helps. Petr Savicky. __ 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

Re: [R] Question on where samples are grouped in rmvnorm{mvtnorm}

2011-05-01 Thread Petr Savicky
?var. Hope this helps. Petr Savicky. __ 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

Re: [R] UNIX-like cut command in R

2011-05-03 Thread Petr Savicky
- function(x, ind) paste(x[ind], collapse= ) vapply(strsplit(x, ), reassemble, character, c(1, 4)) [1] this string this numeric Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do

Re: [R] Simple loop

2011-05-04 Thread Petr Savicky
Petr Savicky. __ 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] Read last line of a file

2011-05-04 Thread Petr Savicky
- readLines(file) strsplit(x[length(x)], +)[[1]][3] Hope this helps. Petr Savicky. __ 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

Re: [R] Simple loop

2011-05-04 Thread Petr Savicky
On Wed, May 04, 2011 at 08:52:07AM -0700, William Dunlap wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Petr Savicky Sent: Wednesday, May 04, 2011 12:51 AM To: r-help@r-project.org Subject: Re: [R] Simple loop

Re: [R] join tables in R

2011-05-04 Thread Petr Savicky
=2004:2006) valid - master[! (master[, 1] %in% train[ ,1]), , drop=FALSE] Hope this helps. Petr Savicky. __ 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

Re: [R] for loop

2011-05-06 Thread Petr Savicky
vector may be obtained using c() from a matrix. The output vector may be reformatted using matrix(). However, for a matrix solution, a more precise description of the question is needed. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list

Re: [R] for loop

2011-05-06 Thread Petr Savicky
. This corresponds to the understanding that odd elements should repeat 7 times and even elements 6 times. However, it is not clear, what the dimension of the output matrix should be. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https

Re: [R] Custom Zero equivalent in R

2011-05-07 Thread Petr Savicky
explicit tests like abs(x) 1e-20. Petr Savicky. __ 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

Re: [R] (subscript) logical subscript too long in using apply

2012-02-17 Thread Petr Savicky
) applies func to the rows of gs. These rows have length 2665, which is equal to the number of columns of data. So, i would expect to use z to select columns, not rows of data. Can you comment on this? Petr Savicky. __ R-help@r-project.org mailing list

Re: [R] How to change the order of columns in a data frame?

2012-02-17 Thread Petr Savicky
))) pos[, order(ind)] X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19 a A0 A1 A2 A3 A4 A5 A6 A7 A8 A9 A10 A11 A12 A13 A14 A15 A16 A17 A18 A19 Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https

Re: [R] covariance

2012-02-17 Thread Petr Savicky
cov_pairwise1(), cov_pairwise2(), cov_complete1(), or cov_complete2(). Probably, other members of the list may correct me, if this is not correct. Basic formulas for the covariance are at Wikipedia http://en.wikipedia.org/wiki/Covariance Hope this helps. Petr Savicky

Re: [R] assigning NULL to a list element

2012-02-18 Thread Petr Savicky
with a/b/c only Hi. Besides the other solutions in this thread, the following also works. append(tmp0, list(d=NULL)) $a [1] 1 $b NULL $c [1] 3 $d NULL Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch

Re: [R] Counting value changes

2012-02-18 Thread Petr Savicky
, since it is not preceded by 0. Hope this helps. Petr Savicky. __ 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

Re: [R] R help

2012-02-19 Thread Petr Savicky
into the memory. Hope this helps. Petr Savicky. __ 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

Re: [R] R help

2012-02-19 Thread Petr Savicky
consists of rnorm(1) and rnorm(m) together. If you have a specific Sigma, describe it and we can discuss, whether an appropriate A can be found. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help

Re: [R] random numbers

2012-02-19 Thread Petr Savicky
) - (G + 1)/2 }, c(0, 1e10))$root y - exp(rnorm(n, sd=sigma)) 2. Check the gini coefficient of the sample using (B). 2*sum(seq(length=n)*sort(y))/(n*sum(y)) - (n+1)/n [1] 0.305003 Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list

Re: [R] Sorting strings

2012-02-20 Thread Petr Savicky
, but : Hi. This neednot be true for strings of different length. For example ab abc become by concatenation with z abcz abz Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting

Re: [R] How to determine a subset of a binary strings?

2012-02-20 Thread Petr Savicky
and packages but no hits. Any ideas? Hi. Try this all(x = y) # [1] TRUE all(z = y) # [1] TRUE all(x = z) # [1] FALSE Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read

Re: [R] Sorting strings

2012-02-20 Thread Petr Savicky
the collation order: ... Hope this helps. Petr Savicky. __ 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

Re: [R] Sorting strings

2012-02-20 Thread Petr Savicky
On Mon, Feb 20, 2012 at 04:56:21PM +0100, Petr Savicky wrote: On Mon, Feb 20, 2012 at 05:55:30AM -0800, statquant2 wrote: I did, but this does not give the answer to my question... Anybody knows how to tweack the behaviour of sort or how to do ? Hi. Try this Sys.setlocale

Re: [R] Disabling shell access through system() possible?

2012-02-20 Thread Petr Savicky
permissions. Petr Savicky. __ 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] Column wise matrix multiplication

2012-02-20 Thread Petr Savicky
- rowProds2(a)) identical(out1, out2) [1] TRUE rbind(t1, t2) user.self sys.self elapsed user.child sys.child t1 0.5500.003 0.553 0 0 t2 0.0490.013 0.062 0 0 Petr Savicky. __ R-help@r

Re: [R] removing particular row from matrix

2012-02-21 Thread Petr Savicky
55 [2,]369 Hope this helps. Petr Savicky. __ 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

Re: [R] In R 2.14.1, what does wrong sign in 'by' argument mean?

2012-02-21 Thread Petr Savicky
. Try to set options(error=utils::recover) before the run. When the error occurs, you can see the values of the variables inside the function, where the error occured. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch

Re: [R] FW: NaN from function

2012-02-23 Thread Petr Savicky
) # [1] 2.220446e-16 2.220446e-16 2.220446e-16 ... Petr Savicky. __ 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

Re: [R] Searching for a pattern within a vector

2012-02-24 Thread Petr Savicky
0 [4,] 0 1 1 [5,] 0 1 1 [6,] 1 1 1 [7,] 1 1 1 [8,] 1 1 1 [9,] 1 1 0 [10,] 1 1 0 Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http

Re: [R] Speeding up accumulation code in large matrix calc?

2012-02-24 Thread Petr Savicky
if the number of rows is large and the number of columns is not, then a solution, which uses a loop over columns, may be better. Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read

Re: [R] Speeding up accumulation code in large matrix calc?

2012-02-24 Thread Petr Savicky
in seq.int(from=2, length=ncol(A)-1)) { curr - ifelse (A[, i-1] == outcome, 0, 1 + curr) B[, i] - curr } # verify all(num.columns.back.since.last.occurence(A, 1) == B) [1] TRUE Hope this helps. Petr Savicky. __ R-help@r-project.org

Re: [R] listing array after loop

2012-02-24 Thread Petr Savicky
the number of file names in file_s is at least 10. Petr Savicky. __ 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

Re: [R] Speeding up accumulation code in large matrix calc?

2012-02-24 Thread Petr Savicky
On Fri, Feb 24, 2012 at 09:06:28PM +0100, Berend Hasselman wrote: [...] I've done some speed tests. t1 - function(m, outcome) { nrows - dim(m)[1] ncols - dim(m)[2] res - matrix(rep.int(0, nrows*ncols), nrow=nrows) for(row in 1:nrows) { for(col in

Re: [R] Speeding up accumulation code in large matrix calc?

2012-02-24 Thread Petr Savicky
On Fri, Feb 24, 2012 at 09:06:28PM +0100, Berend Hasselman wrote: [...] Summary of results Nrow - 100 Ncol - 1000 A - matrix((runif(Ncol*Nrow)0.2)+0, nrow=Nrow) print(rbind(z1,z2,z3,z4,z5,z6)) user.self sys.self elapsed user.child sys.child z1 0.5430.005 0.551 0

Re: [R] which is the fastest way to make data.frame out of a three-dimensional array?

2012-02-25 Thread Petr Savicky
(seq_len(n1), n2*n3 ,dim2 = rep( rep(seq_len(n2), e=n1), n3) , dim3 = rep(seq_len(n3), e = n1*n2) ) Hi. Try this df - data.frame(dat=c(foo), which(foo == foo, arr.ind=TRUE)) This may be less efficient, but easier to remember. Hope this helps. Petr Savicky

Re: [R] which is the fastest way to make data.frame out of a three-dimensional array?

2012-02-25 Thread Petr Savicky
... On the contrary to a previous suggestion with foo==foo, this works also in presence of NA. Hope this helps. Petr Savicky. __ 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

Re: [R] loop for a large database

2012-02-26 Thread Petr Savicky
frame consist of character vectors or from factors? This may be seen by testing class(MyTable[[1]]). Petr Savicky. __ 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

Re: [R] loop for a large database

2012-02-26 Thread Petr Savicky
as follows. x - c(as.matrix(MyTable)) out - unclass(table(factor(x, levels=myvector))) Here, out is a vector of the same length as myvector and out[i] is the frequency of myvector[i] in MyTable. Hope this helps. Petr Savicky. __ R-help@r-project.org

Re: [R] Help needed! Error in setwd(newdir) : cannot change working directory

2012-02-26 Thread Petr Savicky
change working directory Execution halted Try print(newdir) before setwd(newdir). Petr Savicky. __ 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

Re: [R] loop for a large database

2012-02-27 Thread Petr Savicky
On Sun, Feb 26, 2012 at 11:39:01AM -0800, mari681 wrote: SORRY! The data in MyTable are tagsets of photos, like this: V1 V2 V3 V4 V5 V6V7 V8 230green nailpolish barrym 0 00 00 231 ny green

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

2012-02-27 Thread Petr Savicky
paste(df[[1]], df[[2]], df[[3]], sep=\r) and then setdiff() can be better. Hope this helps. Petr Savicky. __ 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

Re: [R] indexing??

2012-02-28 Thread Petr Savicky
5 5 5 3 5 2 5 6 4 [[2]]$yy [1] 4 4 5 4 3 5 2 5 5 3 # 1 is missing [[3]] [[3]]$zz [1] 5 2 5 1 5 1 2 5 5 5 [[3]]$yy [1] 4 2 5 1 5 1 1 4 5 4 # 3 is missing Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list

Re: [R] vlookup type function

2012-02-28 Thread Petr Savicky
in base So the results would be: base         list 2.2  -- 2 3    -- 3 5.2  --  5 Hi. Try the following. unlist(lapply(base, FUN = function(x) max(list[list = x]))) Hope this helps. Petr Savicky. __ R-help@r-project.org mailing

Re: [R] vlookup type function

2012-02-28 Thread Petr Savicky
, 2.2, 3, 5.2, 8) unlist(lapply(base, FUN=function(x) max(list[list = x], -Inf))) [1] -Inf2357 Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting

Re: [R] indexing??

2012-02-28 Thread Petr Savicky
On Tue, Feb 28, 2012 at 08:50:45AM -0800, helin_susam wrote: Dear Petr Pikal and Petr Savicky thank you for your replies.. If the y vector contains different elements my algorithm gives this result; y - c(1,2,3,4,5,6,7,8,9,10) x - c(1,0,0,1,1,0,0,1,1,0) n - length(x) t - matrix

Re: [R] indexing??

2012-02-28 Thread Petr Savicky
On Tue, Feb 28, 2012 at 08:50:45AM -0800, helin_susam wrote: Dear Petr Pikal and Petr Savicky thank you for your replies.. If the y vector contains different elements my algorithm gives this result; y - c(1,2,3,4,5,6,7,8,9,10) x - c(1,0,0,1,1,0,0,1,1,0) n - length(x) t - matrix

Re: [R] indexing??

2012-02-29 Thread Petr Savicky
On Tue, Feb 28, 2012 at 11:42:32AM -0800, helin_susam wrote: Dear Petr Savicky, Actually, this is based on jackknife after bootstrap algorithm. In summary, I have a data set, and I want to compute some values by using this algorithm. Firstly, using bootstrap, I create some bootstrap re

Re: [R] Coding help

2012-02-29 Thread Petr Savicky
not be, what you want. In this case, provide a numerical example. Petr Savicky. __ 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

Re: [R] Trying to eliminate a for loop

2012-02-29 Thread Petr Savicky
is a numeric vector) data.cca - cancor(X,Y) Xcen=0*X for(i in 1:dim(X)[1]){ Xcen[i,]=data.cca$xcenter } Xc = X - Xcen Hi. Is the following, what you are looking for? Xc - sweep(X, 2, data.cca$xcenter) Hope this helps. Petr Savicky

Re: [R] select rows by criteria

2012-03-01 Thread Petr Savicky
will be proportional to choose(n, k), so it will be large even for moderate n, k. It is hard to provide a significant speed up, since some variants of knapsack problem, which is NP-complete, may be reduced to your question. Consequently, it is, in general, NP-complete. Hope this helps. Petr Savicky

  1   2   3   4   5   >