similar to: counting the occurrences of vectors

Displaying 20 results from an estimated 1000 matches similar to: "counting the occurrences of vectors"

2004 Jul 01
3
list structure question
Hi, I have a list in which element is a vector (all of the same length and all numeric). I want to find the mean of the first elements of the vectors, the mean of the second elements of the vectors and so on. Currently I convert the list to a data.frame and apply rowMeans(). But is there a way to to do this directly on the list? I seem to recall a post in which there was such a function (or
2012 Aug 04
3
Head or Tails game
Hi, Reading about a "Heads and Tails" game in http://www.dartmouth.edu/~chance/teaching_aids/books_articles/probability_book/amsbook.mac.pdf Introduction to Probability (Example 1.4, pp. 5-8). You toss a coin 40 times. If heads, Peter wins $1, tails, he loses $1. I think I can do that ok with: winnings <- sum(sample(c(-1,1), 40, replace=TRUE)) But I have to do it 10,000 times
2004 Dec 16
8
counting numbers without replicates in a vector
Hi, I am just wondering if there is an easy way to count in a numeric vector how many numbers don't have replicates. For example, a=c(1,1,2,2,3,4,5), how can I know there are three numbers (3, 4 and 5) without replicates? Thank you! Jun =====
2010 Dec 15
3
Applying function to a TABLE and also "apply, tapply, sapply etc"
Dear R-help forum members, Suppose I have a data-frame having two variables and single data for each of them, as described below. variable_1           variable_2         10                          20 I have written a function, say, 'fun' which uses input 10 and 20 and gives me desired result. fun = function(X, Y)          {          X + Y              #( I am just giving an example of
2010 Jun 29
1
Performance enhancement for ave
library(plyr) n<-100000 grp1<-sample(1:750, n, replace=T) grp2<-sample(1:750, n, replace=T) d<-data.frame(x=rnorm(n), y=rnorm(n), grp1=grp1, grp2=grp2) system.time({ d$avx1 <- ave(d$x, list(d$grp1, d$grp2)) d$avy1 <- ave(d$y, list(d$grp1, d$grp2)) }) # user system elapsed # 39.300 0.279 40.809 system.time({ d$avx2 <- ave(d$x, interaction(d$grp1, d$grp2, drop =
2008 Aug 27
5
Integrate a 1-variable function with 1 parameter (Jose L. Romero)
Hey fellas: I would like to integrate the following function: integrand <- function (x,t) { exp(-2*t)*(2*t)^x/(10*factorial(x)) } with respect to the t variable, from 0 to 10. The variable x here works as a parameter: I would like to integrate the said function for each value of x in 0,1,..,44. I have tried Vectorize to no avail. Thanks in advance, jose romero
2002 Apr 29
1
Garbage collection: RW1041
Have searched through the archives but have been unable to find any related issues - hopefully I'm not bringing up an old topic. Am using RW1041 on a Windows NT on a machine with 1Gb of memory. Have a function doit() that reads in a chunk of data using readBin, performs a regression, saves out coeffs and then returns. When using Rgui with the default memory limit of 256Mb I'm able to
2012 Mar 04
1
hash table clean-up
Hello, I have noticed that the memory usage inside an R session increases as more and more objects with unique names are created, even after they are removed. Here is a small reproducible example: > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 531720 14.2 899071 24.1 818163 21.9 Vcells 247949 1.9 786432 6.0 641735 4.9 > > for (i in 1:100000) { + name <-
2007 Feb 08
2
Timings of function execution in R [was Re: R in Industry]
On 2/8/07, Albrecht, Dr. Stefan (AZ Private Equity Partner) <stefan.albrecht at apep.com> wrote: > Dear all, > > Thanks a lot for your comments. > > I very well agree with you that writing efficient code is about optimisation. The most important rules I know would be: > - vectorization > - pre-definition of vectors, etc. > - use matrix instead of data.frame > - do
2009 Dec 08
4
lower.tail option in pnorm
Hi, I would have thought that these two constructions would produce the same result but they do not. Resp <- rbinom(10, 1, 0.5) Stim <- rep(0:1, 5) mm <- model.matrix(~ Stim) Xb <- mm %*% c(0, 1) ifelse(Resp, log(pnorm(Xb)), log(1 - pnorm(Xb))) pnorm(as.vector(Xb), lower.tail = Resp, log.p = TRUE) > ifelse(Resp, log(pnorm(Xb)), log(1 - pnorm(Xb))) [1] -0.6931472 -1.8410216
2007 Jul 26
2
Large dataset + randomForest
[Please CC me in any replies as I am not currently subscribed to the list. Thanks!] Dear all, I did a bit of searching on the question of large datasets but did not come to a definite conclusion. What I am trying to do is the following: I want to read in a dataset with approx. 100 000 rows and approx 150 columns. The file size is ~ 33MB, which one would deem not too big a file for R.
2011 Sep 02
5
Hessian Matrix Issue
Dear All, I am running a simulation to obtain coverage probability of Wald type confidence intervals for my parameter d in a function of two parameters (mu,d). I am optimizing it using "optim" method "L-BFGS-B" to obtain MLE. As, I want to invert the Hessian matrix to get Standard errors of the two parameter estimates. However, my Hessian matrix at times becomes
2007 Sep 18
1
Problem in extracting EQY_DVD_HIST from Bloomberg
Hi R, Again the problem in Bloomberg, I give the below code, > con = blpConnect(show.days="trading",na.action="previous.days",periodicity="da ily")# connecting Bloomberg > div <- blpGetData(con,"IBM US Equity","EQY_DVD_HIST",start=as.chron(as.Date("01/01/2005", "%m/%d/%Y")),end=as.chron(Sys.Date())) >
2009 Nov 02
2
a prolem with constrOptim
Hi, I apologize for the long message but the problem I encountered can't be stated in a few lines. I am having some problems with the function constrOptim. My goal is to maximize the likelihood of product of K multinomials, each with four catagories under linear constraints on the parameter values. I have found that the function does not work for many data configurations. #The likelihood
2008 Jun 03
3
How to solve a non-linear system of equations using R
Dear R-list members, I've had a hard time trying to solve a non-linear system (nls) of equations which structure for the equation i, i=1,...,4, is as follows: f_i(d_1,d_2,d_3,d_4)-k_i(l,m,s) = 0 (1) In the expression above, both f_i and k_i are known functions and l, m and s are known constants. I would like to estimate the vector d=(d_1,d_2,d_3,d_4) which is solution
2002 Aug 31
1
bug in garbage collector function gc() documentation (PR#1970)
Full_Name: Saket Joshi Version: 1.5.0 OS: Solaris 5.8 Submission from: (NULL) (128.193.38.91) According to the documentation obtained by entering: help.search("gc"), the command gc() forces garbage collection and gives the memory usage statistics along with the trigger values in bytes also interpretted in megabytes. However when I ran gc(), the result was a list giving the memory usage
2003 Dec 06
7
Windows Memory Issues
Hi all, I am currently building an application based on R 1.7.1 (+ compiled C/C++ code + MySql + VB). I am building this application to work on 2 different platforms (Windows XP Professional (500mb memory) and Windows NT 4.0 with service pack 6 (1gb memory)). This is a very memory intensive application performing sophisticated operations on "large" matrices (typically 5000x1500
2001 Sep 21
2
memory usage
Does the following indicate that I have a memory leak? > gc(TRUE) Garbage collection 22891 = 21012+1557+322 (level 2) ... 483257 cons cells free (59%) 11.0 Mbytes of heap free (82%) used (Mb) gc trigger (Mb) Ncells 334906 9.0 818163 21.9 Vcells 309342 2.4 1746173 13.4 > memory.size()/1024/1024 ## in MB [1] 643.8978 > sum(sapply(ls(all.names=TRUE),object.size)) [1] 1776
2000 Feb 11
1
astonishing memory phenomenon
I have a question concerning memory. I understood that R takes a fixed amount of memory at startup (which I can influence with --vsize --nsize) and that gc() shows the memory still free of the total memory reserved for R. However, if I create a long vector of character data, gc() only seem to reflect the space needed for a vector of pointers to char, the space used for the character data itself
2002 Oct 11
1
growing process size in simulation
I came across this in a simulation I ran under 1.6.0: If I do something like R> x <- rnorm(10) R> rval <- NULL R> for(i in 1:100000) rval <- t.test(x)$p.value then the process size remains at about 14M under 1.5.1, but it seems to be almost linearly growing up to more than 100M under 1.6.0. I know that the above simulation is nonsense, but it was the simplest I could come up