similar to: Use 2 "ifelse" to sort data

Displaying 20 results from an estimated 10000 matches similar to: "Use 2 "ifelse" to sort data"

2009 Feb 24
1
Help How to use a loop to do pair comparison
Hi R users, I have a question. How can I use for loop to do pair comparisons. For example, > x<-c(1,2,3) > result<-matrix(data=NA, nrow=choose(3,2), ncol=1) > for(i in 1: length(x)) + { result[i,]<-ifelse(x[i] > x[i+1], yes="Big", no="Small") + result} > result [,1] [1,] "Small" [2,] "Small" [3,] NA
2009 Sep 29
4
Something wrong with my function Please Help
Hi R users, I try to build a function to compute odds ratio and relative risk however something wrong. I stuck for many hours but I really don't know how to solve it. Would someone please give me a hint? > OR.RR<-function(x){ + x <- as.matrix(any(dim(x)==2)) + OR<-(x[1,1]*x[2,2])/(x[1,2]*x[2,1]) + RR<-(x[1,1]/(sum(x[1,])))/(x[2,1]/(sum(x[2,]))) +
2008 Jul 30
2
Repeated Measure ANOVA-Old question
Hi R users, I google the website and I found that there are three ways to perform repeated measure ANOVA: aov, lme and lmer. http://www.mail-archive.com/r-help at stat.math.ethz.ch/msg58502.html But the questions are which one is good to use and how to do post-hoc test? I use the example that is provided in the above link and I try > tt<-aov(p.pa~group*time+Error(subject/time),data=P.PA)
2009 Sep 08
2
strange results in summary and IQR functions
Dear R users, Something is strange in summary and IQR. Suppose, I have a data set and I would like to find the Q1, Q2, Q3 and IQR. x<-c(2,4,11,12,13,15,31,31,37,47) > summary(x) Min. 1st Qu. Median Mean 3rd Qu. Max. 2.00 11.25 14.00 20.30 31.00 47.00 > IQR(x) [1] 19.75 However, I test the same data set in SAS "proc univariate", and SAS shows that
2012 Mar 17
3
rtriang using ifelse statement
Hi All, I want to draw samples (n=4) from one of 2 triangular distributions for each value in a matrix. I am using an ifelse statement to try to define which distribution to draw from. >From the output, I can see that the ifelse statement is choosing the correct distribution, however, my n=4 simulations aren't occurring. Is there a way to adjust the ifelse statement to fix this, or must
2003 Dec 15
1
nls arguments
Hi all, I've got a problem with the nls function. I have an adjustment which works when I fix one of the argument of my function (Xo=150) : *Xo*=150 f<- function (tt*,Xo*,a,b) ifelse(tt<*Xo*,a*exp(-b**Xo*),a*exp(-b*tt)) ajust<-nls(RER~f(tt,*Xo*,a,b),data=data.frame(tt=Ph2[,2*k],RER=Ph2[,2*k+1]),start=list(a=0.5,b=0.014)) But, when I use it as a "normal" parameter (and
2009 Jun 12
1
Please Help pairwise.t.test!!
Hi R users, My question is, If I have 3 groups, A, B, C and I know mean of A =20, B=21, and C=20.5 and I also know the standard error of A =1.1, B=2.2, C=3.2. Plus, I know A has 30 observations, B has 78, C has 45. But I do not have the raw data. Can I use pairwise.t.test to conduct a Bonferroni test? If yes, Could you give me a hint? Thank you so much Chunhao -- View this message in
2010 Mar 10
1
ifelse logic and multiple assignments
I'm a fairly new R user and while I have a solution to my problem I'm wondering if there is a better one. In SAS it's common to use if/then logic along with a "do" statement to make several things happen. While I could do the same thing in R using a "for" loop, and "if" and {}, I've read that loops are less common in R and I wonder if I'm doing
2016 Nov 27
1
ifelse() woes ... can we agree on a ifelse2() ?
Related to the length of 'ifelse' result, I want to say that "example of different return modes" in ?ifelse led me to perceive a wrong thing in the past. ## example of different return modes: yes <- 1:3 no <- pi^(0:3) typeof(ifelse(NA, yes, no)) # logical typeof(ifelse(TRUE, yes, no)) # integer typeof(ifelse(FALSE, yes, no)) # double As
2005 Jun 22
2
Trouble with ifelse and if statement (PR#7962)
Full_Name: Woolton Lee Version: 2.1 OS: windows Submission from: (NULL) (128.118.224.46) I did the following ('g' and 'h' are both numeric vectors) > i <- abs(g-h) creating a vector 'i' with values, > i [1] 0.08 0.00 0.33 0.00 0.00 0.00 0.00 0.33 0.00 0.00 0.08 0.08 0.20 0.00 0.13 Now, I want to create a new vector =1 whenever 'i' = 0.33 and =0
2005 Jun 01
2
A suggestion to improve ifelse behaviour with vector yes/noarguments
> Thomas Lumley wrote: > > On Tue, 31 May 2005, Duncan Murdoch wrote: > > > > > >>M??kinen Jussi wrote: > >> > >>>Dear All, > >>> > >>>I luckily found the following feature (or problem) when tried to > >>>apply > >>>ifelse-function to an ordered data. > >>> > >>> >
2009 Oct 24
2
ifelse
When I run this code from an R-script: ddd = 360 + round ( atan2(-u,-v) / d2r ) print(class(ddd)) print(ddd) ifelse ( ddd>360, ddd-360, ddd ) print(ddd) I get this output: [1] "numeric" [1] 461 213 238 249 251 [1] 461 213 238 249 251 Why does ifelse not change the 461 to 101? I recreated the vector ddd and ran the same ifelse code
2009 Feb 13
2
extracting parts of words or extraxting letter to use in ifelse-func.
Hello I want to make some variables with the ifelse-function, but i don't know how to do it. I want to make these five variables; b2$PRRSvac <- ifelse(b2$status=='A' | b2$status=='Aa',1,0) b2$PRRSdk <- ifelse(b2$status=='B' | b2$status=='Bb',1,0) b2$sanVac <- ifelse(b2$status=='C' | b2$status=='sanAa',1,0) b2$sanDk <-
2018 May 03
1
Proposed speedup of ifelse
I propose a patch to ifelse that leverages anyNA(test) to achieve an improvement in performance. For a test vector of length 10, the change nearly halves the time taken and for a test of length 1 million, there is a tenfold increase in speed. Even for small vectors, the distributions of timings between the old and the proposed ifelse do not intersect. The patch does not intend to change the
2007 Dec 20
1
ifelse problem
Could someone help me with the following code snippet. The results are not what I expect: > Sheet1$Claims[1:10] [1] NA 1 2 NA NA NA NA NA NA NA > Sheet1[1:10,"SubmissionStatus"] [1] Declined Bound Bound Bound Bound Bound Declined Dead Declined [10] Not Taken Levels: Bound Dead Declined Not Taken > Sheet1$Claimsnum <- NA >
2008 Aug 27
1
ifelse() fill order and recycling rules [Sec=Unclassified]
Hi all, Using R v2.7.1, platform i386-pc-mingw32 Can someone please shed some light on the behaviour of ifelse() for me? My intent is to calc relative proportions of z$b, at the same time subsetting z$b based on z$a. I could attack the problem other ways (suggestions welcome) but I am also intrigued by the _order_ in which ifelse seems to assign values, and how recycling works. For instance,
2010 Mar 17
2
How to use "ifelse" to generate random value from a distribution
I need use different parameters of distribution for different case to generate random value, but I use ifelse, the generated value is fixed without change. Here is example data1 y x 1 1 2 2 2 1 3 3 2 4 4 3 5 5 3 6 6 1 7 7 2 8 8 1 9 9 1 10 10 3 11 11 3 12 12 2 ifelse(data1$x==1,rnorm(1,2,1),ifelse(data1$x==2,rnorm(1,-2,1),rnorm(1,110,1))) [1] -1.8042172 0.8478681
2012 Jan 19
3
Establishing groups using something other than ifelse()
Hello all, This is one of those "Is there a better way to do this questions". Say I have a dataframe (df) with a grouping variable (z). This is my base data. Now I know that there is a higher order level of grouping that exist for my group variable. So what I want to do is create a new column that express that higher order level of grouping based on values in the sub-group (z in this
2010 Dec 23
1
with(data.frame,ifelse(___,___,___))
Hello, All, Mac OS 10.6.5 R64 2.11.1 This works as expected: f1 = c(0.084, 0.099, 0) data= data.frame(f1) data$f1=with(data,ifelse(f1==0, 0.0001, f1)) data f1 1 0.0840 2 0.0990 3 0.0001 Substituting ''f1==0'' with ''T'' produces the expected result: f1 = c(0.084, 0.099, 0) data= data.frame(f1) data$f1=with(data,ifelse(T, 0.0001, f1)) data f1 1 1e-04
2011 Jul 11
1
Ifelse statement
Hello everyone, I have a (small) issue. I already googled a lot, so I decided to use ifelse instead of if (){} else{} All the elements seem to work seperately, but combined in the ifelse statement, it doesn't seem to work. #The price function is a function which is normally distributed with only positive answers price<-function() {abs(rnorm(1,10,25))} #Before I use pieceprice in the