similar to: Returning positions of a vector

Displaying 20 results from an estimated 7000 matches similar to: "Returning positions of a vector"

2005 Jun 02
2
overlaying plots
surely this not hard, but i can't figure it out. i'd like to overlay the results of two ecdf's. e.g. xx<--ecdf(x) and yy<--ecdf(y). i'd like to plot xx and yy on the same graph. thanks...mj [[alternative HTML version deleted]]
2005 Nov 09
6
elements in a matrix to a vector
hi all, i'm trying to get elements in a matrix into a vector. i need a "streamlined" way to do it as the way i'm doing it is not very serviceable. an example is a 3x3 matrix like 0 0 3 2 0 0 0 4 0 to a vector like 3 2 4 thanks...mj [[alternative HTML version deleted]]
2007 Nov 16
1
How to save multiple graphs into a single file
Hi, I have searched the archives and help manuals and can not find anything regarding how to save multiple plots/graphs into a single for example, pdf file. There is plenty of discussion etc. about saving a single plot to a single file, but not multiple plots to a single file. Is it possible? I can't want to use lattice, because I have hundreds of plots. So, to keep it simple, let's say
2005 Nov 15
3
Reading in a table with unequal columns
Hi, Wasn't sure how to explain this problem succinctly in a title. I am trying to read in a text file that looks like: 0 1000 175 1 2 3 1 1000 58 0 2 9 2 1000 35 0 1 3 10 3 1000 300 0 2 4 5 10 11 18 4 1000 150 3 5 6 5 1000 100 3 4 6 7 18 6 1000 50 4 5 7 8 7 1000 155 5 6 8 19 8 1000 255 6 7 19 9 1000 200 1 10 12 10 1000 52
2008 Jun 16
1
aggregate() function, strange behavior for augmented data
All, I'm re-running some analysis that has been augmented with additional data. When I use the exact same code for the augmented data, the behavior of the aggregate function is very strange, viz., one of the resulting variables is now coded as a factor while it was coded as numeric for the original data. Unfortunately, I cannot provide a reproducible code example since it only seems to occur
2017 Jun 01
5
Reversing one dimension of an array, in a generalized case
Hi All: I have been looking for an elegant way to do the following, but haven't found it, I have never had a good understanding of any of the "apply" functions. A simplified idea is I have an array, say: junk(5, 10, 3) where (5, 10, 3) give the dimension sizes, and I want to reverse the second dimension, so I could do: junk1 <- junk[, rev(seq_len(10), ] but what I am
2010 Aug 10
4
Function to Define a Function
I am trying to define a general R function that has a function as the output that depends on the user's input arguments (this may make more sense by looking at the toy example below). My real use for this type of code is to allow a user to choose from many parameterizations of the same general model. My "issue" is that when I compile a package with this type of code in it I get a
2017 Jun 01
2
Reversing one dimension of an array, in a generalized case
My error. Clearly I did not do enough testing. z <- array(1:24,dim=2:4) > all.equal(f(z,1),f2(z,1)) [1] TRUE > all.equal(f(z,2),f2(z,2)) [1] TRUE > all.equal(f(z,3),f2(z,3)) [1] "Attributes: < Component ?dim?: Mean relative difference: 0.4444444 >" [2] "Mean relative difference: 0.6109091" # Your earlier example > z <- array(1:120, dim=2:5) >
2017 Jun 01
0
Reversing one dimension of an array, in a generalized case
How about this: f <- function(a,wh){ ## a is the array; wh is the index to be reversed l<- lapply(dim(a),seq_len) l[[wh]]<- rev(l[[wh]]) do.call(`[`,c(list(a),l)) } ## test z <- array(1:120,dim=2:5) ## I omit the printouts f(z,2) f(z,3) Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into
2017 Jun 01
3
Reversing one dimension of an array, in a generalized case
> On 1 Jun 2017, at 22:42, Roy Mendelssohn - NOAA Federal <roy.mendelssohn at noaa.gov> wrote: > > Thanks to all for responses/. There was a question of exactly what was wanted. It is the generalization of the obvious example I gave, > >>>> junk1 <- junk[, rev(seq_len(10), ] > > > so that > > junk[1,1,1 ] = junk1[1,10,1] > junk[1,2,1] =
2010 Jan 21
1
Retrieving an evaluated gradient value (UNCLASSIFIED)
Classification: UNCLASSIFIED Caveats: NONE Dear R users, How can I retrieve an evaluated gradient value from "deriv" function provided below? I want to retrieve b0 value. Appreciate your help. Kyong junk1<-deriv(~(1/b1)*k-b0/b1,"b0",c("k","b0","b1"),formal=T) junk1(k=0,b0=-14.0236,b1=2.44031) [1] 5.746647 attr(, "gradient"):
2007 Dec 27
4
Conditionally incrementing a loop counter
Hi, I am trying a for loop from 1 to 100 by 1. However, if a condition does not get met, I want to "throw away" that iteration. So if my loop is for (i in 1:100) and i is say, 25 and the condition is not met then I don't want i to go up to 26. Is there a way to do that? I can't seem to manually adjust i because from what I understand, R creates 100 long vector and uses that to
2017 Jun 01
3
Reversing one dimension of an array, in a generalized case
Here is an alternative approach using apply(). Note that with apply() you are reversing rows or columns not indices of rows or columns so apply(junk, 2, rev) reverses the values in each column not the column indices. We actually need to use rev() on everything but the index we are interested in reversing: f2 <- function(a, wh) { dims <- seq_len(length(dim(a))) dims <-
2017 Jun 01
0
Reversing one dimension of an array, in a generalized case
Thanks to all for responses/. There was a question of exactly what was wanted. It is the generalization of the obvious example I gave, >>> junk1 <- junk[, rev(seq_len(10), ] so that junk[1,1,1 ] = junk1[1,10,1] junk[1,2,1] = junk1[1,9,1] etc. The genesis of this is the program is downloading data from a variety of sources on (time, altitude, lat, lon) coordinates, but all
2017 Jun 01
0
Reversing one dimension of an array, in a generalized case
?? > z <- array(1:24,dim=2:4) > all.equal(f(z,3),f2(z,3)) [1] "Attributes: < Component ?dim?: Mean relative difference: 0.4444444 >" [2] "Mean relative difference: 0.6109091" In fact, > dim(f(z,3)) [1] 2 3 4 > dim(f2(z,3)) [1] 3 4 2 Have I made some sort of stupid error here? Or have I misunderstood what was wanted? Cheers, Bert Bert Gunter
2017 Jun 01
0
Reversing one dimension of an array, in a generalized case
On the off chance that anyone is still interested, here is the corrected function using aperm(): z <- array(1:120,dim=2:5) f2 <- function(a, wh) { idx <- seq_len(length(dim(a))) dims <- setdiff(idx, wh) idx <- append(idx[-1], idx[1], wh-1) aperm(apply(a, dims, rev), idx) } all.equal(f(z, 1), f2(z, 1)) # [1] TRUE all.equal(f(z, 2), f2(z, 2)) # [1] TRUE
2017 Jun 01
1
Reversing one dimension of an array, in a generalized case
Thanks again. I am going to try the different versions. But I probably won't be able to get to it till next week. This is probably at the point where anything further should be sent to me privately. -Roy > On Jun 1, 2017, at 1:56 PM, David L Carlson <dcarlson at tamu.edu> wrote: > > On the off chance that anyone is still interested, here is the corrected function using
2009 Jan 12
1
Help with storage of each matrix generated in a loop
I need to store each matrix generated in a loop. I've been working with the CUSUM algorithm and I've been trying to implement it in R. What I need to do with my dataset is to create 1000 randomized datasets and cumulative sum them all and store all of those randomized CUSUMed datasets for further analysis and creation of the simulation envelope in the CUSUM chart. But I can't manage
2009 Jul 18
1
Plotting question
Hi I have a data set that needs to be plotted (see below) When I plot it using the simple plot(read_count ~ Cn), I get box plots for the read_count numbers plotted according to Cn. The Cn's on the x-axis are ordered: 10000, 100, 1000, 40, 400, 4000... How do I plot so that Cn is plotted on the x-axis in an ascending order: 40, 60, 80, .......10000? Thanks for your help. Anjan ID
2007 Dec 05
1
Calculating large determinants
I apologise for not including a reproducible example with this query but I hope that I can make things clear without one. I am fitting some finite mixture models to data. Each mixture component has p parameters (p=29 in my application) and there are q components to the mixture. The number of data points is n ~ 1500. I need to select a good q and I have been considering model selection methods