similar to: for loop

Displaying 20 results from an estimated 10000 matches similar to: "for loop"

2010 Sep 11
5
for loop
Hello, I have a simple question: I want to list numbers 1:k, but if k <1, I hope nothing listed. how should we do? k=2 for (i in 1:k)  print(i) [1] 1    # <-correct [1] 2 k=0 for (i in 1:k) print(i) [1] 1      #<---- wrong [1] 0   thanks jian [[alternative HTML version deleted]]
2011 Sep 04
2
Regression coefficient constraints
Hi Guys, Does anyone know how I could constrain my regression coefficients so that they are positive and add up to one? Any help will be greatly appreciated. Kind Regards, Andre [[alternative HTML version deleted]]
2011 May 02
2
vector decreasing by a factor
Hi, I'm quite new to R so this question will sound quite fundamental. I need to create a vector of length 160. The first element should be (1+r)^159 and each element thereafter should decrease by a factor of (1+r) until the 160th element that should be 1. Is there a function similar to seq() but increasing or decreasing by factors? I need to do this in one step i.e, not using loops. Any help
2010 Sep 10
2
survfit question
Hi, I am attempting to graph a Kaplan Meier estimate for some claims using the survfit function. However, I was wondering if it is possible to plot a cdf of the kaplan meier rather than the survival function. Here is some of my code: library(survival) Surv(claimj,censorj==0) survfit(Surv(claimj,censorj==0)~1) surv.all<-survfit(Surv(claimj,censorj==0)~1) summary(surv.all) plot(surv.all)
2012 Jun 30
2
incorrect number of subscripts on matrix
Hi, Wondering if anyone could help me out with this error.Im trying to fill a matrix with random numbers taken from an exponential distribution using a loop: x.3<-matrix(rep(0,3000),nrow=1000,byrow=T)for(i in 1:1000){x[i,]<-rexp(3,rate=2/3)} I get the error message: Error in x[i, ] <- rexp(3, rate = 2/3) : incorrect number of subscripts on matrix Any ideas??? Appreciate any thoughts.
2010 Sep 26
1
acf function
Hi, Im new to R so this question is quite fundamental. Im trying to compare some autocorrelations generated by the acf function to some theoretical correlations. How can I have acces to just the autocorrelations, for computation? This is some of my code: > acf.data<-c(acf(x)) > acf.data This is the R output: $acf , , 1 [,1] [1,] 1.000000000 [2,]
2011 May 14
2
Survreg object
Hi,Just a quick one, does anyone know the command for accessing the standard errors from a survreg object? I can access the coefficients by model$coefficients, but I cant seem to find a command to access the errors. Any help would be greatly appreciated.Regards,Andre [[alternative HTML version deleted]]
2011 May 03
6
Simple loop
Hello everybody, I am beginning with loops and functions and would be glad to have help in the following question: If i have a dataframe like this Site Prof H 1 1 24 1 1 16 1 1 67 1 2 23 1 2 56 1 2 45 2 1 67 2 1 46 And I would like to create a new column that subtracts the minimum of H from H, but for S1 and P1 only
2011 Jan 27
2
help for a loop procedure
Hello everybody! I’m trying to define the optimal number of surveys to detect the highest number of species within a monitoring season/session. To do this I want to run all the possible combinations between a set of samples and to calculate the total number of species for each combination of 2, 3, 4 …n samples events, so that at the end I will be able to define which is the lowest number of
2012 Feb 26
6
loop for a large database
Yes, I am a newbie. I have a data.frame (MyTable) of 1445846 rows and 15 columns with character data. And a character vector (MyVector) of 473491 elements. I want simply to get a data.frame with the count of how many times each element of MyVector appears in MyTable. I've tried a loop with : for (i in 1 : length (myvector)) sum (MyTable== i) but it crashes my computer. I've also
2012 Jun 15
3
moving from loops to apply
Dear subscribers, I have made a simulation using loops rather than apply, simply because the loop function seems more natural to me. However, the current simulation takes forever and I have decided - finally - to learn how to use apply, but - as many other people before me - I am having a hard time changing habits. My current problem is: My current code for the loop is: distances <-
2007 Apr 28
4
pure R code package for Windows
Dear R developers, I am using R under Linux, but I would like to share an extension package with some Windows users. The package contains only data and .R scripts. There is no src directory. So, I think I do not need a Windows machine with C compiler, "make", "sh" and "perl". If I am wrong, please tell me. I tried the following approaches (after verifying the
2011 Feb 02
2
Counter in a For Loop - Efficiency Issue
I have a 32000 x 14 matrix (M) where entry (x, y) corresponds to person x at a discrete time y. I then have a matrix (M2) of 60000 x 2 where each entry is a an event by a person that is in the above 32000 and at a time that is in the range of the discrete time points above. I want to populate the another matrix (M3) such that (x, y) is the number of events of person x between times y-1 and y. This
2006 Oct 11
2
expression as a parameter of binom.test (PR#9288)
Full_Name: Petr Savicky Version: 2.4.0 OS: Fedora Core release 2 Submission from: (NULL) (62.24.91.47) the error is > binom.test(0.56*10000,10000) Error in binom.test(0.56 * 10000, 10000) : 'x' must be nonnegative and integer while > binom.test(5600,10000) yields correct result. The same error occurrs for > binom.test(0.57*10000,10000)
2009 Jul 30
3
user supplied random number generators
?Random.user says (in svn trunk) Optionally, functions \code{user_unif_nseed} and \code{user_unif_seedloc} can be supplied which are called with no arguments and should return pointers to the number of seeds and to an integer array of seeds. Calls to \code{GetRNGstate} and \code{PutRNGstate} will then copy this array to and from \code{.Random.seed}. And it offers as an example void
2009 May 03
1
suggestion for extending ?as.factor
In R-2.10.0, the development version, function as.factor() uses 17 digit precision for conversion of numeric values to character type. This is very good for the consistency of the resulting factor, however, i expect that people will complain about, for example, as.factor(0.3) being [1] 0.29999999999999999 Levels: 0.29999999999999999 I suggest to extend the "Warning" section of
2012 Feb 07
2
Vectorizing a loop
Hello Folks, I'm trying to vectorize a loop that processes rows of a dataframe. It involves lots of conditionals, such as "If column 10 == 3, and if column 3 is True, and both column 5 and 6 are False, then set column 4 to True". So, for example, any ideas about vectorizing the following? df = data.frame( list(a=c(1,2,3,4),
2005 Oct 21
3
make three plot to one plot
Dear all, I want to make three plot below to only one plot together with legend, how can I do that? I have tried with matplot function but I did not succeed. Thanks for your help. Sincerelly, Jan Sabee test.five.x <- c(0.02,0.05,0.07,0.09,0.10,0.12,0.13,0.14,0.16,0.17,0.20,0.21,0.34,0.40) test.five.y <- c(18,12,17,12,3,15,1,5,1,1,3,10,15,10) plot(test.five.x, test.five.y,
2012 Mar 08
4
Correlation between 2 matrices but with subset of variables
Dear All, I have two matrices A (40 x 732) and B (40 x 1230) and would like to calculate correlation between them.  I can use: cor(A,B, method="pearson") to calculate correlation between all possible pairs. But the issue is that there is one-many specific mappings between A and B and I just need to calculate correlations for those pairs (not all). Some variables in A (proteins, say p1)
2002 Jun 20
1
tree construction crashes (PR#1698)
Full_Name: Petr Savicky Version: 1.5.0 OS: SuSE 7.2 Submission from: (NULL) (147.231.6.1) The function tree() from the tree package crashes for certain input data. All the information needed to reproduce the error (data, script, expected error message) may be found at http://www.cs.cas.cz/~savicky/tree_error/tree_error.tgz Exactly the same error appeared at another computer running some RedHat