similar to: ifelse command

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

2011 Aug 30
3
Simulating distribution of max of two die
Hallo I am teaching a very elementary intro course about R, and want to show the students how to find the distribution of the maximum of rolling two balanced die. Is there perhaps a more elegant way to do this, other than the way I am using below? (I would like to show them two ways - the one shown here, and perhaps and improved/elegant approach (showing off the "beauty" of R.
2005 Jul 21
3
vectorising ifelse()
Hi All, is there any chance of vectorising the two ifelse() statements in the following code: for(i in gp){ new[i,1] = ifelse(srow[i]>0, new[srow[i],zippo[i]], sample(1:100, 1, prob =Y1, rep = T)) new[i,2] = ifelse(drow[i]>0, new[drow[i]>0,zappo[i]], sample(1:100, 1, prob =Y1, rep = T)) } Where I am forced to check if the value of drow and srow are >0 for each line... in
2020 Sep 10
5
aplicar codigo
Hola: Como dice Carlos, algo así, por ejemplo: transforma <- function(df) sapply(df, function(x) ifelse(x%in%c("x1","x2","x3"), "prueba1",ifelse(x%in%c("x4","x5","x6"),"prueba2",x))) > transforma(df1)       col1  [1,] "prueba1"  [2,] "prueba1"  [3,] "x11"  [4,]
2007 Mar 02
1
barplot with different color combination for each bar
Hi, I'd like to construct a somewhat unusual barplot. In "barplot" I use beside=F as I'd like to have stacked bars. The height of each bar is always the same. Information in my plot is coded in the color of the bar. I therefore need to be able so assign a different combination (or order) of colors to each individual stacked bar. In the example below, the combination of
2010 Oct 05
3
R-help
Im trying to simulate the rolling of a pair of dice   this is my function: #function to simulate tosses of a pair of dice #from the simulation, the program returns the empirical probability of #observing a double count <- 0 for(j in 1:sim){#begin loop die1 <- sample(1:6,1) print(die1) die2 <- sample(1:6,1) print(die2) count <- ifelse(die1 == die2, count + 1, count) }#end loop emprob
2020 Sep 10
2
aplicar codigo
Yo copio y pego este código y me sale correctamente. Se me ocurre que pueda deberse a la versión de R ¿cuál usas? El 10/09/2020 a las 17:51, Samura . escribió: > Gracias por las respuestas. > > Probé lo de hacer la función y no me salía. Pensaba que hacía algo mal. > Ahora con el código de Marcelino tampoco me sale. > > col1 <- c('x1', 'x2', 'x11',
2020 Nov 04
2
Concatenar secuencia hasta el final con ifelse
Hola, Necesito asignar a cada observación un orden según su posición en un listado, estoy aplicando el siguiente código, pero no se cómo extenderlo para que lo haga hasta el final de las observaciones sin hacerlo manualmente: Data$Order.Page <- ifelse(Data$Order.individual <=5, 1, ifelse(Data$Order.individual<=10, 2, ifelse(Data$Order.individual <=15, 3,... Lo que nos diría es que
2020 Nov 04
2
Concatenar secuencia hasta el final con ifelse
Hola, muchas gracias por contestar, Creo que no es exactamente eso porque a veces la variable Data$Order.individual es común a varias observaciones de la base de datos, es decir, puede haber varias observaciones que tengan valor 1 en esa variable. Si lo hago de la forma que me dices, no se si está teniendo eso en cuenta. La idea es que el código lea qué valor tiene la observación en
2010 Feb 14
4
Problem in performing goodness of fit test in R.
I am trying to perform goodness of fit test using R. I am using this website http://wiener.math.csi.cuny.edu/Statistics/R/simpleR/stat013.html for help. However, I am unable to carry out the test successfully. My code follows. It is taken from the website just mentioned. freq=c(22,21,22,27,22,36) # frequencies obtained after rolling the dice 150 times. prob=c(1,1,1,1,1,1)/6 # specify expected
2013 May 28
3
Nueva consulta
Hola buenas tardes: Vuelvo a solicitar su ayuda porque no puedo saber que pasa. Estoy usando el documento 'Regresión Logística Categor/Tema 4 Cate.pdf como guía y el ejemplo que ustedes conocen de los cangrejos (crab.txt). Cargo los datos, los guardo en un data frame llamado tabla; al pedir tabla[1:5,] obtengo: color spine width satell weight 1 3 3 28.3 8 3050 2 4
2009 Feb 26
1
two colors and putting lines on bar plots
Hi all, I want to represent two categories with one color and have other categories a different color on a bar plot. I can do this using for one category/number using the ifelse call in col but how to extend to two categories/numbers? barplot(dataframe$vector_o_numbers, col=ifelse(dataframe$vector_o_numbers == 00, "red", "black"), names.arg=dataframe$labels) For example if
2006 Oct 02
5
Barplot
Hello, I have used the following data to draw my barplot: BL LR Q 36.35 1.00 1.92 36.91 4.00 0.00 25.70 6.00 0.00 34.38 3.00 1.92 05.32 0.50 0.00 BL<-c(36.35, 36.91, 25.70, 34.38, 05.32) LR<-c(1.00, 4.00, 6.00, 3.00, 0.50) Q<-<(1.92, 0.00, 0.00, 1.92, 0.00) barplot(dt$LR, main='LR Value', col='orange', border='black',
2013 Feb 01
1
x-axis labelling
Hi Folks! I have a question regarding an issue on which I´ve read a few threads but can´t resolve --> Labelling every other tick mark on the x-axis using factors. Here´s an example: db<-data.frame(date=as.factor(c(1:50)),var=rnorm(50)) barplot(db$var,names.arg=levels(db$date),las=2,cex.axis=0.8,cex=0.8) This labels all the tickmarks in my barplot, which is the default behavior. I would
2009 Aug 06
2
Ylim
Hello All: Can anybody tell me what is the problem with my program please. I have an error message as appears below. My program is: ifn <- "Jul08_09.LM" data <- read.table(ifn) ofn <- "Jul.png" bitmap(ofn, type = "png256", width = 30, height = 30, pointsize = 30, bg = "white",res=50) par(mar=c(5, 5, 3, 2),lwd=5)
2012 May 30
5
problem with ifelse
Dear all, ?The code below is used to generate interval censored data but unfortunately there is an error with the ifelse which i am not able to rectify. ?Can somebody help correct it for me. Thank you t<-rexp(20,0.2)? v<-c(0,m,999)? y<-function(t,v){ ? z<-numeric(length(t (( ? ? s<-numeric(length(t (( ? ? ? for(i in 1:length(t)){ ? ? ? ? for(j in 1:length(v-1))? ? ? ? ? { ifelse
2003 May 01
2
What' wrong?
I try to do single proportion test on my category data. Here is my R script: library("ctest") catSignifTest <- function( catFile ) { ############################################################### ## Get the data sets from text file catData <- read.table( catFile ) ncols <- length(catData) nrows <- length(catData[,1]) ncol1 <- ncols - 1 probeNbr
2008 Oct 31
4
[ifelse] how to maintain a value from original matrix without probs?
Dear all, I have a matrix with positive and negative values. >From this I would like to produce 2 matrices: 1st - retaining positives and putting NA in other positions 2nd - retaining negatives and putting NA in other positions and then apply rowMeans for both. I am trying to use the function ifelse in the exemplified form: ifelse(A>0,A,NA) but by putting A as a 2nd parameter it
2003 Nov 12
3
(no subject)
Hi all, I am looking for a clever way to create the following graph using R: I got information on the shares of some subgroups over time (summing up to 1 in each year). The graph I want to create should display the development of the individual shares over time by shading rectangulars for each share in a different color. Is there a clever of doing this? Thanks for your help Stefan
2010 Oct 02
3
Non-Parametric Adventures in R
I just started using R and I'm having all sorts of "fun" trying different things. I'm going to document the different things I'm doing here as a kind of case study. I'm hoping that I'll get help from the community so that I can use R properly. Anyways, in this study, I have demographic data, drug usage data, and side effect data. All of this is loaded into a csv
2019 Mar 06
3
Crear una variable tipo factor a partir de un vector de caracteres
Pero eso es para crear variables binarias tipo 0-1 si el pais pertence a un determinado grupo. Lo que quiero es crear una variable de tipo factor con esos 5 niveles, sabiendo que tengo en el dataframe una variable llamada Country, con el nombre del pais. Gracias On Wed, 6 Mar 2019 at 15:27, Xavier-Andoni Tibau Alberdi < xavitibau en gmail.com> wrote: > Buenas, > > Para ello yo uso