similar to: data frame question

Displaying 20 results from an estimated 3000 matches similar to: "data frame question"

2017 Aug 06
0
data frame question
Your specification is a bit unclear to me, so I'm not sure the below is really what you want. For example, your example seems to imply that a and b must be of the same length, but I do not see that your description requires this. So the following may not be what you want exactly, but one way to do this(there may be cleverer ones!) is to make use of ?rep. Everything else is just fussy detail.
2017 Aug 06
1
data frame question
Hi Andreas, assuming that the increment is always indicated by the same value (in your example 0), this could work: df$a <- cumsum(seq_along(df$b) %in% which(df$b == 0)) df HTH, Ulrik On Sun, 6 Aug 2017 at 18:06 Bert Gunter <bgunter.4567 at gmail.com> wrote: > Your specification is a bit unclear to me, so I'm not sure the below > is really what you want. For example, your
2013 Mar 20
2
remove specific number of rows from a matrix
Dear All,   sorry, got stuck again on the following: let us say we have:   a <-c(1:5) b <-c(6:10) d <-cbind(a,b)     from d I would like to remove total number of rows based on the length of f. So if:   f <-c(1)   my result is working great with the following solution:   d[-length(f),]   so I get: a b [1,] 2 7 [2,] 3 8 [3,] 4 9 [4,] 5 10 but if I do: f <-c(1,2) then I get: 
2013 Jun 18
2
find closest value in a vector based on another vector values
Dear All, would you please provide your thoughts on the following: let us say I have: a <-c(1,5,8,15,32,69) b <-c(8.5,33) and I would like to extract from "a" the two values that are closest to the values in "b", where the length of this vectors may change but b will allways be shorter than "a". So at the end based on this example I should have the result
2013 Feb 26
2
Help on a code
Dear List,   I have the following code:   x <-c(0, 13.8333333333333, 38.1666666666667, 62.1666666666667, 85.9166666666667, 108.916666666667) y <-c(1.77, 2.39, 3, 2.65, 2.62, 1.8) Interpolated <- approx(x, y,xout=0:tail(x, n=1),method="linear") plot(Interpolated)   in this code x is time in hours (cumulative), and y is a biological variable. I am using linear interpolation
2012 Aug 31
3
Help on numerical object and ifelse function
Dear All,   this is probably an easy one but I can not get a handle on it:   x <-c(1,2,3,4,5) y <-c(6,7,8,9,10) z <-15 w <-ifelse(z>14,x,y)   this will give me a value of 1 for w. What I would like to get is the whole string of x, so that w would become a numeric object of 5 characters exactly the same as x.   Apreciate the help,   Sincerely,   Andras [[alternative HTML version
2012 Sep 02
3
Help on finding specific columns in matrix
Dear All,   I have a matrix with 33 columns and 5000 rows. I would like to find 2 specific columns in the set: the one that holds the highest values and the one that holds the lowest values. In this case the column's mean would be apropriate to use to try to find those specific columns because each columns mean is different and they all change together based on the same "change of rate
2013 Jan 25
5
Loop question?
Dear All   I have the following data (somewhat simplyfied):   TINF <-1 a <-c(500,750,1000,1250,1500,1750,2000) b <-c(8,12,18,24,36,48,60,72,96)   following function:   infcprodessa <-function (D, tin, tau, ts)   (D * (1 - exp(-0.048 * tin))/(tin * (0.048*79) * (1 - exp(-0.048 * tau)))) * exp(-0.048 * (ts - tin)) z <-sapply(1:1, function(n) infcprodessa(1000,TINF,12,12-TINF))   is
2012 Jun 07
4
"Re-creating" distributions
Dear All,   I often have to work with certain models in which I try to "reproduce" a distribution the best I can with very little known information avaible. Is there a package or function in R that could best reproduce a probability distribution using only the mean, median and SD values availble without knowing the actual distribution type to begin with and/or the covariance matrix (for
2012 Dec 17
3
simplifying code
Dear All,   I was wondering if you could help me with the following: I have the code:   tin <-0.5 tau <-24 output0 <-10 TIMELOW <-tin TIMEHIGH <-1*tau TIME1 <-c(seq(TIMELOW,TIMEHIGH, by = sign(TIMEHIGH-TIMELOW)*(tau-tin)/3))   then I would like to calculate:   cp1 <-output0*exp(-0.3*TIME1[1]) cp2 <-output0*exp(-0.3*TIME1[2]) cp3 <-output0*exp(-0.3*TIME1[3]) cp4
2017 Jun 15
2
"reverse" quantile function
David, thanks for the response. In your response the quantile function (if I see correctly) runs on the columns versus I need to run it on the rows, which is an easy fix, but that is not exactly what I had in mind... essentially we can remove t() from my original code to make "res" look like this: res<-apply(z, 1, quantile, probs=c(0.3)) but after all maybe I did not explain
2012 Sep 08
3
Apply a function to columns of a matrix
Dear All,   as a follow up to my previous e-mail (I think I am getting closer...):   I am trying to apply the trapezoidal functions to a matric column by column. I have the following code:   a <-matrix(c(1:100),ncol=10) b <-matrix(c(2,4,6,8,10,12,14,16,18,20))   apply(a,2,function(b,a) sum(diff(b)*(a[-1]+a[-length(a)]))/2)   for some reason i get an error message: Error in FUN(newX[[, i],
2012 Sep 12
2
Help on converting a Sweave document to PDF
Dear All,   I am working with a Sweave document to be converted into PDF using Rstudio. It seems to me that my R code will also show up after conversion, which I would like not to happen. Is there a way to specify a command that I could place on the beggining and at the end of the R code that would allow R to recognize the area where my R code is and would ignor it when the data is converted?  
2013 Mar 20
3
how to skip part of the code
Dear All,   another quick question, this one is on skipping part of my code, so let us say:   a <-5 b <-2 e <-0   d <-a+b f <-a-b   what I would like to do is to have R NOT to calculate the value for d in case the value of e equals to zero (essentially skip that "chunk"), but instead move on to calculate te value for f. In the code I am working with the value of e changes,
2008 Jul 11
1
Suggestion: 20% speed up of which() with two-character mod
Hi, by replacing 'll' with 'wh' in the source code for base::which() one gets ~20% speed up for *named logical vectors*. CURRENT CODE: which <- function(x, arr.ind = FALSE) { if(!is.logical(x)) stop("argument to 'which' is not logical") wh <- seq_along(x)[ll <- x & !is.na(x)] m <- length(wh) dl <- dim(x) if (is.null(dl)
2012 Dec 01
3
screen if a value is within range
Dear all,   could you please give me some pointers on how I could make R screen for a value if it falls within a certain range? I looked at the subset function, but is not doing it, perhaps because I only have 1 value to screen?   aptreciate the input   ex: a <-16.5 I would like to screen to see if a is within the range of 15 to 20, (which it is:-)), and I would like the code to return a value
2017 Jun 16
2
"reverse" quantile function
Peter, thanks, very nice, this will work for me... could you also help with setting up the code to run the on liner "approx(sort(x), seq(0,1,,length(x)), q)$y" on the rows of a data frame using my example above? So if I cbind z and res,? df<-cbind(z,res) the "x" in your one liner would be the first 4 column values of each row and "q" is the last (5fth) column
2017 Jun 16
0
"reverse" quantile function
Peter, thanks, very nice, this will work for me... could you also help with setting up the code to run the on liner "approx(sort(x), seq(0,1,,length(x)), q)$y" on the rows of a data frame using my example above? So if I cbind z and res, df<-cbind(z,res) the "x" in your one liner would be the first 4 column values of each row and "q" is the last (5fth) column
2017 Jun 16
0
"reverse" quantile function
It would depend on which one of the 9 quantile definitions you are using. The discontinuous ones aren't invertible, and the continuous ones won't be either, if there are ties in the data. This said, it should just be a matter of setting up the inverse of a piecewise linear function. To set ideas, try x <- rnorm(5) curve(quantile(x,p), xname="p") The breakpoints for the
2012 Aug 30
2
help on plot on the log scale but showing original values on axis
dear All   I am trying to plot the following with the x axis on the log scale, but I would like the original x values to show up as labels:   x <-c(0.25,0.5,1,2,4,8,16,32) y <-c(1,1,1,1,0.9,0.8,0.6,0.2)   plot(log(x),y,type="b")   here I would like the labels 0.25,0.5,1,2,4,8,16, and 32 to show on the plot at their respective "log scale" location   apreciate the help,