similar to: ifelse help?

Displaying 20 results from an estimated 20000 matches similar to: "ifelse help?"

2008 Dec 22
2
How can I avoid nested 'for' loops or quicken the process?
Hi All, I'm still pretty new to using R - and I was hoping I might be able to get some advice as to how to use 'apply' or a similar function instead of using nested for loops. Right now I have a script which uses nested for loops similar to this: i <- 1 for(a in Alpha) { for (b in Beta) { for (c in Gamma) { for (d in Delta) { for (e in Epsilon) { Output[i] <-
2005 Jan 11
1
Nested ifelse - is there a better way?
Dear r-help, I'm interested in finding a better way to add a column to a data frame when calculating the new column requires more than one conditional. For example, if I wanted to associate a character string in {"Pos","Neg","Zero"} with each number in the following data frame: > d <- data.frame(num = -2:2) > d num 1 -2 2 -1 3 0 4 1 5 2 I
2008 Dec 18
2
Contextstack overlow
All - I have a number of rows that I am assigning length classes to via l.class<-with(wae, ifelse((Length>=120)&(Length<130),"125", ifelse((Length>=130)&(Length<140),"135", ifelse((Length>=140)&(Length<150),"145", ifelse((Length>=150)&(Length<160),"155",
2008 Aug 14
2
Determining cause of error?
This is both a specific question and a general one. First, I am running 'fitdistr' from library(MASS) and I get the following: Error in fitdistr(templist, "weibull") : optimization failed What is the cause of the error? How can I tell? Can I just catch this error, report it and move to the next set of data (eat the exception)? Thank you. Kevin
2008 May 27
4
help with simple function
I have a matrix of frequency counts from 0-160. x<-as.matrix(c(0,1,0,0,1,0,0,0,1,0,0,0,0,1)) I would like to apply a function creating a new column (x[,2])containing values equal to: a) log(x[m,1]) if x[m,1] > 0; and b) for all x[m,1]= 0, log(next x[m,1] > 0 / count of preceding zero values +1) for example, x[1,2] should equal log(x[2,1]/2) = log(1/2) = -0.6931472 whereas x[3,2] should
2009 Nov 16
3
Cluster analysis: hclust manipulation possible?
I am doing cluster analysis [hclust(Dist, method="average")] on data that potentially contains redundant objects. As expected, the inclusion of redundant objects affects the clustering result, i.e., the data a1, = a2, = a3, b, c, d, e1, = e2 is likely to cluster differently from the same data without the redundancy, i.e., a1, b, c, d, e1. This is apparent when the outcome is visualized
2008 Jun 13
1
Looping, Control Flow & Conditional Statements
Dear R Group: I have little experience using R and even less experience with control flow type questions. See the following code: a1 = c(0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0) for(i in 1:1){ sx <- paste("a",i,sep="") s <- eval(parse(text = paste("a",i,sep=""))) {g = numeric(length(s)) k =
2009 Jan 08
1
cosinor analysis
Hallo, I didnĀ“t found any facilities for Halbergs cosinor analysis in R. This analysis is well known in the Chronobiology as the least square approximation of time series using cosine function of known period (in my case of 24hours-period). I tried to write a script but crashed... Can you give me some advices, please!? Thanks Anne Berger Institute of Zoo- and Wildlife Research, Berlin, Germany
2008 Dec 04
1
Formula parsing and updating
Hi all, I can't come over a problem with formula. Suppose I have a coxmod model with the following formula: > somemod$formula Surv(lebzeit, tot == 1) ~ sex + (alter >= 65) + diff3k + zelltyp_k_c + q_nuc_3k + kar_k80_g80 + stadium and I want to drop the stadium explanatory variable from the model with > update(somemod, ". ~ . - stadium") I get the following messages:
2008 Dec 11
3
check if a certain ... argument has been passed on to my user-defined function
Hi, How can I check if a certain ... argument has been passed on to my user-defined function or not? foo <- function(data, ...) { ### here I want to check whether xlab was passed with the ... arguments ### or if the ... arguments did not contain an xlab argument } I tried missing(xlab) , exists(xlab) and several other things but did not find a solution. TIA, Mark
2006 Sep 09
2
duplication matrix
Dear R-list members, Just wondering if there is any way to compute the duplication matrix in R. I tried to search for it but only found functions "xpnd" and "vech". Basically for a symmetric n by n matrix A, the duplication matrix D_n is a matrix of dimension n^2 by n(n+1)/2 such that D_n vech(A)= c(A), where c(A) just vectorizes A. The duplication matrix is defined on page
2007 Jun 14
1
R programming question
Dear All., I've created R-code for which a user will be asked to choose between 2 analyses. I've written one function for each type of analysis. Within each function, the users is prompted to enter information. An example is: cat("Enter value for lower Linf :\n") L1<-scan(n=1) cat("Enter value for upper Linf :\n") L2<-scan(n=1)
2008 Dec 27
2
Object name vectcor as function input argument?
Dear R-helpers: I am new to R and ran into the following question and would appreicate your advice very much. My question: How to use a character vector that records object names as function input argument? I asked this question very recently and was advised to use get(). get() works when passing one single object name. but it does not work when passing multiple object names. For example, I
2009 Dec 02
2
Error when running Conditional Logit Model
Dear R-helpers, I am very new to R and trying to run the conditional logit model using "clogit " command. I have more than 4000 observations in my dataset and try to predict the dependent variable from 14 independent variables. My command is as follows clmtest1 <- clogit(Pin~Income+Bus+Pop+Urbpro+Health+Student+Grad+NE+NW+NCC+SCC+CH+SE+MRD+strata(IDD),data=clmdata) However, it
2009 Jul 14
1
Simulation functions for underdispered Poisson and binomial distributions
Dear R users I would like to simulate underdispersed Poisson and binomial distributions somehow. I know you can do this for overdispersed counterparts - using rnbinom() for Poisson and rbetabinom() for binomial. Could anyone share functions to do this? Or please share some tips for modifying existing functions to achieve this. Thank you very much for your help and time Shinichi
2010 Jun 28
6
Basic question - more efficient method than loop?
I'm guessing there's a more efficient way to do the following using the index features of R. Appreciate any thoughts.... for (i in 1:nrow(dbs1)){ if(dbs1$Payor[i] %in% Payor.Group.Medicaid) dbs1$Payor.Group[i] = "Medicaid" if(dbs1$Payor[i] %in% Payor.Group.Medicare) dbs1$Payor.Group[i] = "Medicare" if(dbs1$Payor[i] %in% Payor.Group.Commercial)
2008 Nov 25
2
creating a new vecotr in a for loop
I have consulted the intro and nabble but have not found an answer to what should be a simple question, here goes: I am doing a crosscheck of a data frame and pulling out a single value based on an inputted value ie based on x i will select y, or if x =2 then my code returns 7. x y 1 4 2 7 3 10 4 2 My code currently iterates through for as many times as the length of the x
2010 Nov 23
6
the first. from SAS in R
Is there any similar function in R to the first. in SAS? What it dose is: Lets say we have this table: a b c 1 1 5 1 0 2 2 0 2 2 0 NA 2 9 2 3 1 3 and then I want do to do one thing the first time the number 1 appers in a and something else the secund time 1 appers in a and so on. so something similar to: if first.a { a$d<-1 }else{ a$d<-0 } This would give me
2006 Dec 29
5
coded to categorical variables in a large dataset
I am working with a dataset where there are 5 possible outcomes (coded 1:5), I would like to create 5 categorical variables (event1...event5). I am using a for loop an if statements, but I have a large dataset( approx 100,000 rows) it takes quite a bit of time, is there a way to speed this up? Here is some sample code of what I am currently doing. test2 <-rep(seq(1:5),2000) event1 <-
2006 Jul 19
3
Fitting a distribution to peaks in histogram
Hello list! I would like to fit a distribution to each of the peaks in a histogram, such as this: http://photos1.blogger.com/blogger/7029/2724/1600/DU145-Bax3-Bcl-xL.png . The peaks are identified using Petr Pikal peaks function ( http://finzi.psych.upenn.edu/R/Rhelp02a/archive/33097.html), but after that I am quite stuck. Any idea as to how I can: Fit a distribution to each peak Integrate the