similar to: R: looping

Displaying 20 results from an estimated 10000 matches similar to: "R: looping"

2005 Jun 15
2
need help on computing double summation
Dear helpers in this forum, This is a clarified version of my previous questions in this forum. I really need your generous help on this issue. > Suppose I have the following data set: > > id x y > 023 1 2 > 023 2 5 > 023 4 6 > 023 5 7 > 412 2 5 > 412 3 4 > 412 4 6 > 412 7 9 > 220 5 7 > 220 4 8 > 220 9 8 > ...... > Now I want to compute the
2002 Dec 06
6
fast code
Hello, I have two vectors x1 and x2 both in increasing order. I want to select the x1[j]th entry which is the max min of the x2[i]th entry. I can do this using if and for statements but is there a quick way to do it without running a loop? Thank you in advance, Pantelis
2001 Nov 13
1
Selecting transitive couples
Dear list, I'm trying to improve the following process: Let pairs be a 2 col matrix of integers such as: 2 5 3 6 4 56 5 2 6 8 7 56 8 6 etc. My goal is to select the transitive pairs, i.e., in the above example: 2 5 (because there is 5 2 as well) 6 8 (because there is 8 6 as well) The task is simple with a for loop, but can anybody suggest a "genuine R" solution? (That is, a
2005 Jan 21
4
which.pmin?
I have two vectors (k.floor and k.ceiling) of integers of the same length, and a function (fpr). b <- 10:40 k.floor <- floor(log(2) * b) k.ceiling <- ceiling(log(2) * b) fpr.floor <- fpr(b, k.floor) fpr.ceiling <- fpr(b, k.ceiling) If R had a element-wise ternary function, I'd like to do something like this: (fpr.floor < fpr.ceiling) ? k.floor :
2005 Jun 06
2
intervals and data frames
Dear R people: I have a vector which runs from -1 to 1, by .1, inclusively. Easy to set up. x <- seq(-1,1,.1) I then sample 3 numbers from x. y <- sample(x, 3) Suppose one of my values is -0.7. I want to set up an interval around that y1 <- pmax(y-0.1,-1) y2 <- pmin(y+0.1,1) For the value -.7, the interval will run from -.8 to -.6. There will be several intervals. Again, nothing
2003 Jul 18
2
create a vector looping over a frame
Hello, I have a data.frame > names(popA) [1] "Year" "Series" "Age" "WM" "WF" "HM" "HF" "BM" [9] "BF" "IM" "IF" "AM" "AF" "Yr" how do i loop over a subset of variables in this frame to create a vector of
2024 Feb 27
2
converting MATLAB -> R | element-wise operation
Why anything but sweep? The fundamental data type in Matlab is a matrix... they don't have vectors, they have Nx1 matrices and 1xM matrices. Vectors don't have any concept of "row" vs. "column". Straight division is always elementwise with recycling as needed, and matrices are really vectors in row-major order: 1 2 3 4 5 6 is really 1 4 2 5 3 6 and when you do
2004 Oct 28
2
array problem and for looping
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/r-help/attachments/20041028/dbf887a9/attachment.pl -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: random1.txt Url: https://stat.ethz.ch/pipermail/r-help/attachments/20041028/dbf887a9/random1.txt
2005 Sep 13
11
if() command
Hi everyone ! Could you please help me with this problem ? I??ve trying to write a code that assign to a variable the content from another, but all I??ve got is a message error. For example: if (age <=10) {group == 1} else if (age > 10 & age <= 20) {group == 2} else {group == 3} Syntax error Or if (age <=10) {group == 1} else (age > 10 & age <= 20) {group == 2}
2007 Mar 30
1
Using split() several times in a row?
Hi, fellow R users. I have a question about sapply and split combination. I have a big dataframe (40000 observations, 21 variables). First variable (factor) is "date" and it is in format "8.29.97", that is, I have monthly data. Second variable (also factor) has levels 1 to 6 (fractiles 1 to 5 and missing value with code 6). The other 19 variables are numeric. For each month I
2009 Mar 17
2
sweep?
I am having a hard time understanding just what 'sweep' does. The documentation states: Return an array obtained from an input array by sweeping out a summary statistic. So what does it mean "weeping out a summary statistic"? Thank you. Kevin
2008 Apr 27
1
parallel max, min, and median of dataframe columns
Hello, all, I have a dataframe of three rows and umpteen columns. I want to show the maximum, minimum, and median with a vertical line and a central dot (I'd use a boxplot, but with only three data points, that's overkill; I can't just use points, because of overlap and some of the other data plotted on the graph). This works: > boxplot(data_frame,
2024 Feb 27
4
converting MATLAB -> R | element-wise operation
So, trying to convert a very long, somewhat technical bit of lin alg MATLAB code to R. Most of it working, but raninto a stumbling block that is probaably simple enough for someone to explain. Basically, trying to 'line up' MATLAB results from an element-wise division of a matrix by a vector with R output. Here is a simplified version of the MATLAB code I'm translating: NN = [1,
2007 Feb 27
3
looping
Greetings: I am looking for some help (probably really basic) with looping. What I want to do is repeatedly sample observations (about 100 per sample) from a large dataset (100,000 observations). I would like the samples labelled sample.1, sample.2, and so on (or some other suitably simple naming scheme). To do this manually I would >smp.1 <- sample(100000, 100) >sample.1 <-
2010 Dec 22
4
vectorised recovery of strsplit value ??
Dear Guru's My first steps with R have ground to a halt! I have a vector of sample identifiers > sampleIDs [1] "D1_1" "D1_2" "D1_3" "D1_4" "D1_5" "D1_6" "D1_7" "D1_8" [9] "D1_9" "D1_10" "D1_11" "D1_12" "F1_13" "F1_14"
2008 Sep 27
1
Problem to male an Index in looping
Hi, I am trying to use (i) as an index but R considers it as a function and not as text. To be more specific I would like for example to estimate some regressions named qrnox1, qrnox2, qrnox3,..... and so on. But when I am using qrnox(i) ot qrnox[i] it tries to find the ith element of vector qrnox. The thing is that I want to estimate the qrnoxi regression and not the qrnox(i) function or
2024 Feb 29
2
[External] converting MATLAB -> R | element-wise operation
I decided to do a direct comparison of transpose and sweep. library(microbenchmark) NN <- matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, byrow = TRUE) # Example matrix lambda <- c(2, 3, 4) # Example vector colNN <- t(NN) microbenchmark( sweep = sweep(NN, 2, lambda, "/"), transpose = t(t(NN)/lambda), colNN = colNN/lambda ) Unit: nanoseconds expr min lq
2010 Sep 21
5
Combined plot: Scatter + density plot
Hi, in order to save space for a publication, it would be nice to have a combined scatter and density plot similar to what is shows on http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=78 I wonder if anybody perhaps has already developed code for this and is willing to share. This is the reproducible code for the histogram version obtained from the site: def.par <-
2010 Dec 22
0
Rcpp 0.9.0 and RcppClassic 0.9.0
===== Summary ===== Version 0.9.0 of the Rcpp package is now on CRAN and its mirrors. This release marks another step in the development of the package, and a few key points are highlighted below. More details are in the NEWS and ChangeLog files included in the package. ===== Overview ===== Rcpp is an R package and associated C++ library that facilitates integration of C++ code in R
2010 Dec 22
0
Rcpp 0.9.0 and RcppClassic 0.9.0
===== Summary ===== Version 0.9.0 of the Rcpp package is now on CRAN and its mirrors. This release marks another step in the development of the package, and a few key points are highlighted below. More details are in the NEWS and ChangeLog files included in the package. ===== Overview ===== Rcpp is an R package and associated C++ library that facilitates integration of C++ code in R