similar to: Iteration in R

Displaying 20 results from an estimated 60000 matches similar to: "Iteration in R"

2007 Jun 26
2
how to iterate
for the following example dataset:- Category Variable 1 127 1 261 1 142 1 183 1 234 1 162 2 173 2 321 2 168 2 197 2 213 2 261 3 198 3 126 3 167 3 154 3 134 3 187 3 109 3 210 I have performed Anova on the measured variable (column#2) for the groups 1,2&3 (column#1). Now I want to randomize the values in C#2 and reperform the test, say, a hundred times. Please suggest a way for this
2009 Apr 21
3
ggplot2 - boxplot of variables / columns
Hi, ggplot/qplot is great - it has really helped me do some nice things. However, simple boxplot of different columns/variables is a bit tricky, because of (i think) qplot's generic Y conditional on X input form. Se below. # Some data: a <- rnorm(100) b <- rnorm(100,1,2) c <- rnorm(100,2,0.5) # normal boxplot of a,b,c boxplot(a,b,c) # Looks good library(ggplot2) # loads qqplot2 #
2011 Jul 21
2
Printing the loop number for each iteration
Hi all, I have a lengthy 'for' loop and for each loop I want to track the iteration number that is currently going on. For this, I have tried following: > for (i in 1:10) { + DumDat <- rnorm(1000) + cat("iteration:", i, " \n") + } iteration: 1 iteration: 2 iteration: 3 iteration: 4 iteration: 5 iteration: 6 iteration: 7 iteration: 8
2011 Sep 03
1
Loop with random sampling and write.table
Hi! I need to perform this simple sampling function several hundred times: x1=as.character(rnorm(1000, 100, 15)) x2=as.character(rnorm(1000, 150, 10)) y1=as.data.frame(x1,x2) sample1=as.data.frame(sample(y1$x1, 12, replace = FALSE, prob = NULL)) sample1 write.table(sample1, "sample1.txt", sep=" ",row.names=F,quote=F) My knowledge of loops is quite low. How can I produce 100
2013 Apr 18
5
Subsetting a large number into smaller numbers and find the largest product
Hello, I have a big number lets say of around hundred digits. I want to subset that big number into consecutive number of 5 digits and find the product of those 5 digits. For example my first 5 digit number would be 73167. I need to check the product of the individual numbers in 73167 and so on. The sample number is as follows:
2011 Dec 04
4
equating approximate values
Hello List, I am having trouble finding the command for my problem. I have two arrays x and y. now i would like to compare the values of x and y and then get the index of x which is exactly or approximately equal(+/- some value ) to the values in y. x <- runif(100,min=0,max=5) y <- runif(10,min=0,max=5) the threshold value(+/-) value can vary. for this example lets take it to be .5
2004 Oct 28
3
Quick data-manipulation question
I have a list of data frames and I want to concatenate them into a single data frame, basically appending all of the data frames to each other (they are all the same shape, in terms of columns). I'm looking for a nice way to do that. I can of course just consecutively rbind them to a "master" dataframe, but I have 22,000 such data frames, each with a few hundred rows, so this
2010 Jul 30
2
(no subject)
hello, i am new to R and trying to calculate the beta coefficient for standard linear regression for a series of randomly generated numbers. I have created this loop, but it runs really slow, is there a way to improve it? #number of simulations n.k<-999 #create the matrix for regression coefficients generated from #random data beta<-matrix(0,1,n.k+1) e<-matrix(0,tslength,n.k+1) for(k
2011 Nov 23
2
Is there an easier way to iterate over multiple data frames in R?
> for (d in paste('df', 1:3, sep='')) { + assign(d, as.data.frame(replicate(3, rnorm(4)))) + } > dats = list(df1,df2,df3) > for (i in 1:length(dats)) { + names(dats[[i]]) = c('w', 'l', 'h') + } > dats [[1]] w l h 1 1.24319239 -0.05543649 0.05409178 2 0.05124331 -1.89346950 0.33896273 3 -1.69686777 -0.35963008
2009 Jul 23
2
alternative to rbind within a loop
Hi, I often have to do this: select a folder (directory) containing a few hundred data files in csv format (up to 1000 files, in fact) open each file, transform some character variables in date-tiime format make into a dataframe (involves getting rid of a few variables I don't need concatenate to the master dataframe that will eventually contain the data from all the files in the
2008 Jul 23
1
Q re iterating a process and appending results to output file
Greetings. This is very basic but we can't figure it out. The following simple code counts how many values land in the "tail" (below a quantile) of a standardized normal distribution of random numbers. First two commands are inputs: > c <-0.05 > i <-2500 Second two commands are formulas I want to repeat many times (sort of like an Excel/VBA macro) using those same
2012 Jul 05
4
Exclude missing values on only 1 variable
Hello, I have many hundred variables in my longitudinal dataset and lots of missings. In order to plot data I need to remove missings. If I do > data <- na.omit(data) that will reduce my dataset to 2% of its original size ;) So I only need to listwise delete missings on 3 variables (the ones I am plotting). data$variable1 <-na.omit(data$variable1) does not work. Thank you
2011 Apr 25
1
Trouble Passing a for loop variable (iteration #) to a data frame
Greetings - I am working on a piece of code to simulate vehicle times in and out in each of a number of parking spaces. At this stage, my code basically does what it is supposed to do but for the sequential number of each new parking event for a given space (i.e., the index of the loop variable). Instead of passing the index of the loop variable (iter) to the data frame, it passes the value
2004 Sep 13
2
calculating memory usage
I am comparing two different algorithms in terms of speed and memory usage. I can calculate the processing time with proc.time() as follows but am not sure how to calculate the memory usage. ptm <- proc.time() x <- rnorm(1000000) proc.time() - ptm I would like to be within R itself since I will test the algorithm several hundred times and in batch mode. So manually looking up
2012 May 30
3
alternative generator for normal distributed variables
Hello, currently I'm working on a model based on Monte-Carlo-Simulations. I observed that a generated normal distributed times series using rnorm(100,mean=0,sd=1) is far away from being not autocorrelated. Is there any other gerenator implemented in R, which might solve my problem? -- View this message in context:
2012 Feb 29
2
function for filtering and deleting vector entries
Dear helpers I have two data sets saved as vectors (temperature and velocity). Now I need to "take out" a span of temperature and its corresponding velocity in the other vector. How can I achieve that? I tried to write a function,which takes a vector entry and then decides wether to delete the temperature entry or not and simultaneously doing so with same entry in the velocity
2010 Dec 10
3
(no subject)
Hi R-help, I am trying to find a way to select five highest values in data frame according some variable. I will demonstrate: c X1 X2 1 1 1 2 1 2 3 1 3 4 1 4 5 1 5 6 1 6 7 1 7 8 1 8 9 1 9 10 1 10 11 2 11 12 2 12 13 2 13 14 2 14 15 2 15 16 2 16 17 2 17 18 2 18 19 2 19 20 2 20 21 2 21 22 2 22 23 2 23 24 2 24 25 2 25 So I
2013 Mar 20
3
highlight overlapping region of two densities
Hi all. I would like to highlight overlapping regions of two densities and I could not find a way to do it. Here is the sample code: myd <- c(2,4,5, 4,3,2,2,3,3,3,2,3,3,4,2,4,3,3,3,2,2.5, 2, 3,3, 2.3, 3, 3, 2, 3) myd1 <- myd-2 plot(range(density(myd)$x, density(myd1)$x), range(density(myd)$y, density(myd1)$y), type = "n") lines(density(myd), col=1, lwd=4)
2001 Jul 24
3
strange slowness of plot
I just ran into this strange behavior. y <- rnorm(1000) x <- seq(0, length=length(y)) plot(x, y, type='l', lty=1) - instantaneous plot(x, y, type='l', lty=2) - 18s plotting lines + 15s plotting axes = 33s plot(x, y, type='l', lty=3) - 76s ,, + 75s ,, = 151s plot(x, y, type='l', lty=4) -
2011 Mar 14
2
data.frame transformation
Hi R users, I have following data frame df<-data.frame(q1=c(0,0,33.33,"check"),q2=c(0,33.33,"check",9.156), q3=c("check","check",25,100),q4=c(7.123,35,100,"check")) and i would like to replace every element that is less then 10 with . (dot) in order to obtain this: q1 q2 q3 q4 1 . . check . 2 . 33.33 check 35