Displaying 20 results from an estimated 10000 matches similar to: "How to get rid of loop?"
2005 May 25
3
Rounding fractional numbers to nearest fraction
Hi all,
I've got a matrix of fractional data that is all positive and greater than
zero that I would like to "loosely" classify, for lack of a better word. It
looks something like this :
1.07 1.11 1.27 1.59 0.97 0.76
2.23 0.98 0.71 0.88 1.19 1.02
What I'm looking for is a way to round these numbers to the nearest 0.25,
i.e. the above matrix would be
2007 Nov 20
2
as.character(seq(-.35,.95,.1))
> as.character(seq(-.25,.95,.1))
[1] "-0.25" "-0.15" "-0.05" "0.05" "0.15" "0.25" "0.35" "0.45"
"0.55" "0.65" "0.75" "0.85" "0.95"
> as.character(seq(-.35,.95,.1))
[1] "-0.35" "-0.25"
2006 Jul 24
3
random section of samples based on group membership
Hi all,
I have a matrix of 474 rows (samples) with 565 columns (variables).
each of the 474 samples belong to one of 120 groups, with the
groupings as a column in the above matrix. For example, the group
column would be:
1
1
1
2
2
2
.
.
.
120
120
I want to randomly select one from each group. Not all the groups
have the same number of samples, some have 4, some 3 etc. Is there a
function to
2011 Mar 24
1
Two matrix loop
Hi,
I'm trying to create a distance matrix. And it works out somewhat ok. However, I suspect that there are
some efficiency issues with my efforts. Plz have a look at this:
donor <- matrix(c(3,1,2,3,3,1,4,3,5,1,3,2), ncol=4)
receiver <-
matrix(c(1,4,3,2,4,3,1,5,1,3,2,1,4,5,3,5,1,3,2,4,5,1,2,3,1,4,5,5,1,2,1,3,4,3,2,5,5,1,4,2,5,4,3,2), ncol=4)
The above creates my two matrices. I have
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
2009 Jun 16
3
How to subset my dataframe? (a bit tricky)
Hi R-helpers,
I would like to subset my dataframe, keeping only those rows which
satisfy the following conditions:
1) the string "dnv" is found in at least one column;
2) the value in the column previous to the one "dnv" is found in is not "0"
Here's what my data look like:
??? POND_ID 2009-05-07 2009-05-15 2009-05-21 2009-05-28 2009-06-04
4 ? ? ? 101 ? ? ?
2008 Apr 23
2
Can I get rid of this for loop using apply?
Hey all,
The code below creates a partial dependence plot for the variable x1 in the
linear model y ~ x1 + x1^2 + x2.
I have noticed that the for loop in the code takes a long time to run if the
size of the data is increased. Is there a way to change the for loop into
an apply statement? The tricky part is that I need to change the values of
x1 in each step of the loop to give me the
2010 Jul 20
2
Problem with command apply
I try to utilize some operations on rows in a matrix using command 'apply'
but find a problem.
First I write a simple function to normalize a vector (ignore error
handling) as follows:
normalize = function( v ) {
return( ( v-min(v) ) / ( max(v) - min(v) ) )
}
The function works fine for a vector:
> normalize( 1:5 )
[1] 0.00 0.25 0.50 0.75 1.00
Then I generate a matrix:
> a =
2011 Jan 11
5
A question on dummy variable
Dear all, I would like to ask one question related to statistics, for
specifically on defining dummy variables. As of now, I have come across 3
different kind of dummy variables (assuming I am working with Seasonal
dummy, and number of season is 4):
> dummy1 <- diag(4)
> for(i in 1:3) dummy1 <- rbind(dummy1, diag(4))
> dummy1 <- dummy1[,-4]
>
> dummy2 <- dummy1
>
2006 Aug 11
1
x tick labels - sparse?
Hi,
I'm stuck on creating a plot with x tick labels for every Nth tick
mark - how is that done? I don't see a simple solution to this in
help(plot) or help(par) and what I've tried is not working, eg, the
following does not work, although it seems intuitive to me that it
should work:
x <- seq(-100,1000,25)
y <- x * x
% find all the x values that are multiples of 100
tmp <-
2006 Jun 25
1
Puzzled with contour()
Folks,
The contour() function wants x and y to be in increasing order. I have
a situation where I have a grid in x and y, and associated z values,
which looks like this:
x y z
[1,] 0.00 20 1.000
[2,] 0.00 30 1.000
[3,] 0.00 40 1.000
[4,] 0.00 50 1.000
[5,] 0.00 60 1.000
[6,] 0.00 70 1.000
[7,] 0.00 80 0.000
[8,] 0.00 90
2011 Nov 08
2
Sorting Panel Data by Time
I have panel data in the following form:
TIME X1 S1
1 1 0.99
1 2 0.50
1 3 0.01
2 3 0.99
2 1 0.99
2 2 0.25
3 3 0.75
3 2 0.50
3 1 0.25
... ... ......
And desire a new vector of observations in which one column (S1 above) is
sorted for each second from least to largest.
That
2008 Jan 08
1
using mapply()
useR's,
This is a follow up question to one I previously asked. Consider the
3-element list below
> res
[[1]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[,13] [,14]
[1,] NA NA NA 1.25 0.25 0.75 NA NA NA NA NA NA 1.25
0.25
[2,] 1.25 0.25 0.75 NA NA NA NA NA NA 1.25 0.25 0.75 NA
NA
[3,] NA NA NA NA NA
2008 Jan 08
1
using lapply()
useR's,
I am trying to find a quick way to change some values in a list that are
subject to a condition to be NA. Consider the 3x1 matrix:
delta <- matrix(c(2.5,2.5,1), nrow = 1)
And consider the list named v that has 3 elements
> v
v[[1]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[,13] [,14]
[1,] 4.25 3.25 2.25 1.25 0.25 0.75 1.75 2.75 3.75 4.25
2008 Jan 11
3
changing the values in a list
useR's,
Does anyone know of an efficient way to change the values in a list to
different numbers stored in an object? For example, consider the following:
y <- matrix(c(20, 13, 25, 10, 17), ncol = 1)
> res
[[1]]
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
[,13] [,14]
[1,] NA NA NA 1.25 0.25 0.75 NA NA NA NA NA NA 1.25
0.25
[2,]
2004 Sep 14
3
Signs of loadings from princomp on Windows
I start a clean session of R 1.9.1 on Windows and I run the following code:
> library(MASS)
> data(painters)
> pca.painters <- princomp(painters[ ,1:4])
> loadings(pca.painters)
Loadings:
Comp.1 Comp.2 Comp.3 Comp.4
Composition 0.484 -0.376 0.784 -0.101
Drawing 0.424 0.187 -0.280 -0.841
Colour -0.381 -0.845 -0.211 -0.310
Expression 0.664 -0.330 -0.513
2013 Jul 08
2
Segmentar archivos en R (Antonio José Sáez Castillo)
Estimado Mauricio Monsalvo
Le paso una idea, no es un código muy lindo que digamos, pero al correrlo
seguramente se dará cuenta de mi sugerencia.
datos<-c(2,3,4,5,6,7,8)
quantile(datos)
quantile(datos,probs = c(0.25, 0.75, 0.85, 0.90, 0.95))
as.matrix(quantile(datos,probs = c(0.25, 0.75, 0.85, 0.90, 0.95)))
as.data.frame(quantile(datos,probs = c(0.25, 0.75, 0.85, 0.90, 0.95)))
# ¿ y si solo
2013 May 27
1
Question about subsetting S4 object in ROCR
Dear list
I'm testing a predictor and I produced nice performance plots with ROCR
package utilizing the 3 standard command
pred <- prediction(predictions, labels)
perf <- performance(pred, measure = "tpr", x.measure = "fpr")
plot(perf, col=rainbow(10))
The pred object and the perfo object are S4
with the following slots
An object of class "performance"
2013 Jul 08
1
Segmentar archivos en R (Antonio José Sáez Castillo)
Habría que buscar la vuelta, yo no lo se, pero posiblemente lo siguiente da una pista.
Nota: al mismo código le sume una línea al final
datos<-c(2,3,4,5,6,7,8)
quantile(datos)
quantile(datos,probs = c(0.25, 0.75, 0.85, 0.90, 0.95))
as.matrix(quantile(datos,probs = c(0.25, 0.75, 0.85, 0.90, 0.95)))
as.data.frame(quantile(datos,probs = c(0.25, 0.75, 0.85, 0.90, 0.95)))
# ¿ y si solo solicita
2018 Apr 19
4
create multiple categorical variables in a data frame using a loop
Hi All,
I want to create a categorical variable, cat.pfoa, in the file of pfas.pheno (a data frame) based on log2pfoa values. I can do it using the following code.
pfas.pheno <-within(pfas.pheno, {cat.pfoa<-NA
cat.pfoa[pfas.pheno$log2pfoa <=quantile(pfas.pheno$log2pfoa,0.25, na.rm =T)]<-0
cat.pfoa[pfas.pheno$log2pfoa >=quantile(pfas.pheno$log2pfoa,0.75, na.rm =T)]<-2