Re: [R] if-else that returns vector

2023-10-13 Thread Christofer Bogaso
This is very interesting. Thanks for sharing. On Fri, Oct 13, 2023 at 10:25 AM Richard O'Keefe wrote: > > ?ifelse > 'ifelse' returns a value with the same shape as 'test' which is > filled with elements selected from either 'yes' or 'no' depending > on whether the element of 'test' is '

Re: [R] if-else that returns vector

2023-10-12 Thread Richard O'Keefe
?ifelse 'ifelse' returns a value with the same shape as 'test' which is filled with elements selected from either 'yes' or 'no' depending on whether the element of 'test' is 'TRUE' or 'FALSE'. This is actually rather startling, because elsewhere in the S (R) language, operands are normal

Re: [R] if-else that returns vector

2023-10-12 Thread Rui Barradas
Às 21:22 de 12/10/2023, Christofer Bogaso escreveu: Hi, Following expression returns only the first element ifelse(T, c(1,2,3), c(5,6)) However I am looking for some one-liner expression like above which will return the entire vector. Is there any way to achieve this? ___

Re: [R] if-else that returns vector

2023-10-12 Thread Jeff Newmiller via R-help
What a strange question... ifelse returns a vector (all data in R is vectors... some have length 1, but length zero is also possible, as are longer vectors) that is exactly as long as the logical vector that you give it, filled with elements from the respective positions in the vectors supplied

Re: [R] if-else that returns vector

2023-10-12 Thread Ben Bolker
how about if(T) c(1,2,3) else c(5,6) ? On 2023-10-12 4:22 p.m., Christofer Bogaso wrote: Hi, Following expression returns only the first element ifelse(T, c(1,2,3), c(5,6)) However I am looking for some one-liner expression like above which will return the entire vector. Is there any way

[R] if-else that returns vector

2023-10-12 Thread Christofer Bogaso
Hi, Following expression returns only the first element ifelse(T, c(1,2,3), c(5,6)) However I am looking for some one-liner expression like above which will return the entire vector. Is there any way to achieve this? __ R-help@r-project.org mailing l

Re: [R] if else statement adjustemtn

2020-06-15 Thread Ana Marija
HI Jim thank you so much! This is amazing answer!!! Ana On Sat, Jun 13, 2020 at 4:09 AM Jim Lemon wrote: > > Right, back from shopping. Since you have fourteen rows containing NAs > and you only want seven, we can infer that half of them must go. As > they are neatly divided into seven rows in

Re: [R] if else statement adjustemtn

2020-06-15 Thread Rasmus Liland
On 2020-06-13 19:09 +1000, Jim Lemon wrote: > Right, back from shopping. Since you have fourteen rows containing NAs > and you only want seven, we can infer that half of them must go. As > they are neatly divided into seven rows in which only one NA appears > and seven in which two stare meaningles

Re: [R] if else statement adjustemtn

2020-06-13 Thread Márk Szalai
Dear Ana, pmax could also fit here. pmax(b$FLASER, b$PLASER, na.rm = TRUE) Bests, Mark > -- > > Message: 21 > Date: Sat, 13 Jun 2020 19:09:11 +1000 > From: Jim Lemon > To: sokovic.anamar...@gmail.com > Cc: Rasmus Liland , r-help >

Re: [R] if else statement adjustemtn

2020-06-13 Thread Jim Lemon
Right, back from shopping. Since you have fourteen rows containing NAs and you only want seven, we can infer that half of them must go. As they are neatly divided into seven rows in which only one NA appears and seven in which two stare meaninglessly out at us. I will assume that the latter are the

Re: [R] if else statement adjustemtn

2020-06-12 Thread Ana Marija
Great idea! Here it is: > b[is.na(b$FLASER) | is.na(b$PLASER),] FID IID FLASER PLASER pheno 1: fam1837 G1837 1 NA 2 2: fam2410 G2410 NA NA 2 3: fam2838 G2838 NA 2 2 4: fam3367 G3367 1 NA 2 5: fam3410 G3410 1 NA 2 6: fam

Re: [R] if else statement adjustemtn

2020-06-12 Thread Jim Lemon
Since you have only a few troublesome NA values, if you look at them, or even better, post them: b[is.na(b$FLASER) | is.na(b$PLASER),] perhaps we can work out the appropriate logic to get rid of only the ones you don't want. Jim On Sat, Jun 13, 2020 at 12:50 PM Ana Marija wrote: > > Hi Rasmus,

Re: [R] if else statement adjustemtn

2020-06-12 Thread Ana Marija
Hi Rasmus, thank you for getting back to be, the command your provided seems to add all 11 NAs to 2s > b$pheno <- + ifelse(b$PLASER==2 | + b$FLASER==2 | + is.na(b$PLASER) | + is.na(b$PLASER) & b$FLASER %in% 1:2 | + is.na

Re: [R] if else statement adjustemtn

2020-06-12 Thread Rasmus Liland
On 2020-06-13 11:30 +1000, Jim Lemon wrote: > On Fri, Jun 12, 2020 at 8:06 PM Jim Lemon wrote: > > On Sat, Jun 13, 2020 at 10:46 AM Ana Marija wrote: > > > > > > I am trying to make a new column > > > "pheno" so that I reduce the number > > > of NAs > > > > it looks like those two NA values in >

Re: [R] if else statement adjustemtn

2020-06-12 Thread Jim Lemon
Obviously my guess was wrong. I thought you wanted to impute the value of "pheno" from FLASER if PLASER was missing. From just your summary table, it's hard to guess the distribution of NA values. My guess that the two undesirable NAs were cases where PLASER was missing and FLASER was 2. My tactic

Re: [R] if else statement adjustemtn

2020-06-12 Thread Ana Marija
Hi Jim, I tried it: > b$pheno<-ifelse(b$PLASER==2 | b$FLASER==2 |is.na(b$PLASER) & b$FLASER == > 2,2,1) > table(b$pheno,exclude = NULL) 12 859 828 11 > b$pheno<-ifelse(b$PLASER==2 | b$FLASER==2 |is.na(b$FLASER) & b$PLASER == > 2,2,1) > table(b$pheno,exclude = NULL) 12 859

Re: [R] if else statement adjustemtn

2020-06-12 Thread Jim Lemon
Hi Ana, >From your desired result, it looks like those two NA values in PLASER are the ones you want to drop. If so, try this: b$pheno<-ifelse(b$PLASER==2 | b$FLASER==2 | is.na(b$PLASER) & b$FLASER == 2,2,1) and if I have it the wrong way round, swap FLASER and PLASER in the bit I have added. J

[R] if else statement adjustemtn

2020-06-12 Thread Ana Marija
Hello I have a data frame like this: > head(b) FID IID FLASER PLASER 1: fam1000 G1000 1 1 2: fam1001 G1001 1 1 3: fam1003 G1003 1 2 4: fam1005 G1005 1 1 5: fam1009 G1009 1 1 6: fam1052 G1052 1 1 ... > table(b$PLASER,b$FLASER, e

Re: [R] if else statement

2020-05-05 Thread PIKAL Petr
Hi another possible version b$pheno <- ((b$FLASER==2) | (b$PLASER==2))+1 Cheers Petr > -Original Message- > From: R-help On Behalf Of Rui Barradas > Sent: Monday, May 4, 2020 8:32 PM > To: sokovic.anamar...@gmail.com; r-help > Subject: Re: [R] if else statement >

Re: [R] if else statement

2020-05-04 Thread Richard O'Keefe
Your ifelse expression looks fine. What goes wrong with it? On Tue, 5 May 2020 at 05:16, Ana Marija wrote: > > Hello, > > I have a data frame like this: > > > head(b) >FID IID FLASER PLASER > 1: fam1000 G1000 1 1 > 2: fam1001 G1001 1 1 > 3: fam1003 G1003 1

Re: [R] if else statement

2020-05-04 Thread Rui Barradas
Hello, Here is a way, using logical indices. b$pheno <- NA b$pheno[b$FLASER == 1 & b$PLASER == 1] <- 1 b$pheno[b$FLASER == 2 | b$PLASER == 2] <- 2 Hope this helps, Rui Barradas Às 18:15 de 04/05/20, Ana Marija escreveu: Hello, I have a data frame like this: head(b) FID IID FLA

Re: [R] if else statement

2020-05-04 Thread Ana Marija
Thank you for the tip about table function, it seems correct: > table(b$FLASER, b$PLASER, exclude = NULL) 1 2 1836 6916 2 14 708 0 45 28 > table(b$pheno,exclude = NULL) 12 836 828 34 On Mon, May 4, 2020 at 12:45 PM Jeff Newmiller wrote: > T

Re: [R] if else statement

2020-05-04 Thread Jeff Newmiller
To expand on Patrick's response... You can use the expand.grid function to generate a test table containing all combinations. However, we would not be in a position to verify that the results you get when you apply your logic to the test table are what you want... you know the requirements much

Re: [R] if else statement

2020-05-04 Thread Patrick (Malone Quantitative)
"I tried this but I am not sure if this is correct:" Does it provide the expected result for all possible combinations of 1/2/NA for both variables? On Mon, May 4, 2020 at 1:16 PM Ana Marija wrote: > Hello, > > I have a data frame like this: > > > head(b) >FID IID FLASER PLASER > 1: f

[R] if else statement

2020-05-04 Thread Ana Marija
Hello, I have a data frame like this: > head(b) FID IID FLASER PLASER 1: fam1000 G1000 1 1 2: fam1001 G1001 1 1 3: fam1003 G1003 1 2 4: fam1005 G1005 1 1 5: fam1009 G1009 NA 2 6: fam1052 G1052 1 1 ... > unique(b$PLASER) [1] 1

Re: [R] if else with 4 conditions problem

2018-05-27 Thread Rui Barradas
Hello, It's just a sequence of ifelse instructions. dat <- read.table(text = " A B 1 1 1 0 0 1 0 0 ", header = TRUE) dat$A1 <- ifelse(dat$A == 1 & dat$B == 1, 1, 0) dat$A2 <- ifelse(dat$A == 1 & dat$B == 0, 1,

[R] if else with 4 conditions problem

2018-05-27 Thread smart hendsome via R-help
Hi everyone, I have two columns:    A               B    1               1   1               0    0               1    0               0 I have 4 categories which are: 1) if A = 1 and B =1 then A1 = 1, else A2 = 0, A3 = 0, A4 = 0 2) if A = 1 and B =0 then A1 = 0, else A2 =1, A3 = 0, A4 = 0 3) if

Re: [R] if/else help

2016-09-22 Thread Crombie, Burnette N
Thanks very much for your detailed reply to my post. Very helpful/useful tool(s) you’ve provide me. Best wishes, B. From: William Dunlap [mailto:wdun...@tibco.com] Sent: Wednesday, September 21, 2016 10:48 AM To: Crombie, Burnette N Cc: r-help@r-project.org Subject: Re: [R] if/else help If

Re: [R] if/else help

2016-09-22 Thread Crombie, Burnette N
Thank you for your time, Don. Exactly what I was looking for - a one-liner. Feedback from others on this post has been good to expand my knowledge, though. I'm too old for homework but have just started using R if/else, loops, and functions and trying to get the hang of them. Best w

Re: [R] if/else help

2016-09-21 Thread David Winsemius
> On Sep 21, 2016, at 8:26 AM, MacQueen, Don wrote: > > Hopefully this is not a homework question. > > The other responses are fine, but I would suggest the simplest way to do > exactly what you ask is > > > if (!exists('r4')) r4 <- data.frame(a=0, b=0, c=0, d='x') > > > The exists() functi

Re: [R] if/else help

2016-09-21 Thread MacQueen, Don
Hopefully this is not a homework question. The other responses are fine, but I would suggest the simplest way to do exactly what you ask is if (!exists('r4')) r4 <- data.frame(a=0, b=0, c=0, d='x') The exists() function requires a character string for its first argument, i.e., the name of the

Re: [R] if/else help

2016-09-21 Thread William Dunlap via R-help
If you write your code as functions you can avoid the nasty 'if(exists("x"))x<-...' business this by writing default values for arguments to your function. They will be computed only when they are used. E.g., analyzeData <- function(a=0, b=0, c=0, d="x", r4 = data.frame(a, b, c, d)) { summa

Re: [R] if/else help

2016-09-21 Thread David Winsemius
> On Sep 20, 2016, at 12:31 PM, Crombie, Burnette N wrote: > > If a data.frame (r4) does not exist in my R environment, I would like to > create it before I move on to the next step in my script. How do I make that > happen? Here is what I want to do from a code perspective: > > if (exists(r

Re: [R] if/else help

2016-09-21 Thread Jeff Newmiller
Get rid of the commas? Get rid of the get() function call? Get rid of the cbind() function call? Post using plain text format so the HTML doesn't screw up code? Read the Posting Guide? All of these ideas have merit IMHO... -- Sent from my phone. Please excuse my brevity. On September 20, 2016

[R] if/else help

2016-09-20 Thread Crombie, Burnette N
If a data.frame (r4) does not exist in my R environment, I would like to create it before I move on to the next step in my script. How do I make that happen? Here is what I want to do from a code perspective: if (exists(r4)) { is.data.frame(get(r4)) } else { a <- 0, b <- 0, c <- 0, d <- "x", r4

Re: [R] if else condition - help

2016-05-23 Thread Martin Maechler
> jim holtman > on Sun, 22 May 2016 16:47:06 -0400 writes: > if you want to use 'ifelse', here is a way: hmm, why should he want that ? The OP did mention that it's about somewhat large objects, so efficiency is one of the considerations : ifelse() is often convenient and nicely

Re: [R] if else condition - help

2016-05-22 Thread jim holtman
if you want to use 'ifelse', here is a way: > k = + structure(c(0.0990217544905328, 1.60623837694539, -0.104331330281166, + -2.91485614212114, -0.108388742328104, -1.41670341534772, -1.70609114096417, + 2.92018951284015, 0.201868946570178, 0.907637296638577, -0.403004972105994, + -2.4771801580322

Re: [R] if else condition - help

2016-05-22 Thread Dylan Keenan
Try this: > sign(ifelse(abs(k)<=1.5, 0, k)) C1 C2 C3 C4 A 0 0 0 0 B 1 0 0 0 C 0 -1 0 0 D -1 1 -1 -1 On Sun, May 22, 2016 at 2:00 PM Adrian Johnson wrote: > Hi group: > I am having difficulty with if else condition. I kindly request some help. > > I have a matrix k > > > k >

Re: [R] if else condition - help

2016-05-22 Thread David Winsemius
> On May 22, 2016, at 11:23 AM, Adrian Johnson > wrote: > > Thank you both Dylan and Wray. > > since my matrix is quite large and for simplicity in downstream > operation, i will use sign function. thanks a lot. > > On Sun, May 22, 2016 at 2:12 PM, Dylan Keenan wrote: >> Try this: >> >>> si

Re: [R] if else condition - help

2016-05-22 Thread Adrian Johnson
Thank you both Dylan and Wray. since my matrix is quite large and for simplicity in downstream operation, i will use sign function. thanks a lot. On Sun, May 22, 2016 at 2:12 PM, Dylan Keenan wrote: > Try this: > >> sign(ifelse(abs(k)<=1.5, 0, k)) > > > C1 C2 C3 C4 > A 0 0 0 0 > B 1 0 0

Re: [R] if else condition - help

2016-05-22 Thread WRAY NICHOLAS
Hi Adrian I'm not sure that you need to use the ifelse here. You can simply assign values ina vector or matrix using a simple condition -- here is a simple example: v<-c(4,5,6,7) v1<-v v1[]<-0 v1[v<5]<--1 v1[v>6]<-1 v1 Nick > > On 22 May 2016 at 18:58 Adrian Johnson wrote: > > > Hi

[R] if else condition - help

2016-05-22 Thread Adrian Johnson
Hi group: I am having difficulty with if else condition. I kindly request some help. I have a matrix k > k C1 C2 C3 C4 A 0.09902175 -0.1083887 0.2018689 -0.3546167 B 1.60623838 -1.4167034 0.9076373 -0.3161138 C -0.10433133 -1.7060911 -0.4030050 1.0153297 D

Re: [R] If else

2015-10-31 Thread Rolf Turner
Ted: You are either being deliberately obtuse or playing Devil's advocate or just stirring. It is clear from his/her posts that the OP has limited understanding of both R and statistics. Your sophisticated philosophising about the possibility of "three sexes" is very unlikely to have anyth

Re: [R] If else

2015-10-31 Thread Jim Lemon
8:23:05 AM PDT, Val wrote: > >>>>> Hi All, > >>>>> > >>>>> > >>>>> Yes I need to change to numeric because I am preparing a data set > >>>>> for > >>>>> further analysis. The variable to be changed

Re: [R] If else

2015-10-31 Thread Duncan Murdoch
>>>>> numeric >>>>> (in this case, sex) will be a response variable. Some records have >>>>> missing >>>>> observation on sex and it is blank. >>>>> id sex >>>>> 1 >>>>> 2 >>>&g

Re: [R] If else

2015-10-31 Thread Val
on sex and it is blank. > >>> > id sex > >>> > 1 > >>> > 2 > >>> > 3 M > >>> > 4 F > >>> > 5 M > >>> > 6 F > >>> > 7 F > >>&g

Re: [R] If else

2015-10-31 Thread Ted Harding
F >>> > >>> >I am reading the data like this >>> > >>> >mydata <- read.csv(header=TRUE, text=', sep=", ") >>> > id sex >>> > 1 NA >>> > 2 NA >>> > 3 M >>

Re: [R] If else

2015-10-31 Thread Jeff Newmiller
>> > 7 F >> > >> >The data set is huge (>250,000) >> > >> > >> >I want the output like this >> > >> > id sexsex1 >> > 1 NA0 >> > 2 NA 0 >> > 3 M 1 >> &

Re: [R] If else

2015-10-31 Thread Val
F 2 > > 7 F 2 > > > >Thank you in advance > > > > > >On Sat, Oct 31, 2015 at 5:59 AM, John Kane wrote: > > > >> In line. > >> > >> John Kane > >> Kingston ON Canada > >> > >> > >> > -

Re: [R] If else

2015-10-31 Thread Jeff Newmiller
2 > >Thank you in advance > > >On Sat, Oct 31, 2015 at 5:59 AM, John Kane wrote: > >> In line. >> >> John Kane >> Kingston ON Canada >> >> >> > -Original Message- >> > From: valkr...@gmail.com >> > Sent:

Re: [R] If else

2015-10-31 Thread Val
ada > > > > -Original Message- > > From: valkr...@gmail.com > > Sent: Fri, 30 Oct 2015 20:40:03 -0500 > > To: istaz...@gmail.com > > Subject: Re: [R] If else > > > > I am trying to change the mydata$sex from character to numeric > > Wh

Re: [R] If else

2015-10-31 Thread John Kane
In line. John Kane Kingston ON Canada > -Original Message- > From: valkr...@gmail.com > Sent: Fri, 30 Oct 2015 20:40:03 -0500 > To: istaz...@gmail.com > Subject: Re: [R] If else > > I am trying to change the mydata$sex from character to numeric W

Re: [R] If else

2015-10-30 Thread Val
I am trying to change the mydata$sex from character to numeric I want teh out put like id sex 1 NA 0 2 NA 0 3 M 1 4 F 2 5 M1 6 F 2 7 F2 mydata$sex1 <- 0 if(mydata$sex =="M " ){ mydata$sex1<-1 } else { mydata$sex1<-2

Re: [R] If else

2015-10-30 Thread Ista Zahn
Using numeric for missing sounds like asking for trouble. But if you must, something like mydata$confusingWillCauseProblemsLater <- ifelse( is.na(mydata$sex), 0, as.numeric(factor(mydata$sex, levels = c("M", "F" should do it. Best, Ista On Fri, Oct 30, 20

[R] If else

2015-10-30 Thread Val
Hi all, Iam trying to change character to numeric but have probelm mydata <- read.table(header=TRUE, text=', sep=" " id sex 1 NA 2 NA 3 M 4 F 5 M 6 F 7 F ') if sex is missing then sex=0; if sex is"M" then sex=1; if sex is"F" then sex=

Re: [R] if else statement for rain data to define zero for dry and one to wet

2015-06-07 Thread roslinazairimah zakaria
t;> >> Dennis >> >> >> On Sat, Jun 6, 2015 at 12:50 AM, Jim Lemon wrote: >> > Hi rosalinazairimah, >> > I think the problem is that you are using "if" instead of "ifelse". Try >> this: >> > >> > wet_dry<-func

Re: [R] if else statement for rain data to define zero for dry and one to wet

2015-06-06 Thread William Dunlap
; > wet_dry<-function(x,thresh=0.1) { > > for(column in 1:dim(x)[2]) x[,column]<-ifelse(x[,column]>=thresh,1,0) > > return(x) > > } > > wet_dry(dt) > > > > and see what you get. > > > > Also, why can I read your message perfectly while ev

Re: [R] if else statement for rain data to define zero for dry and one to wet

2015-06-06 Thread Dennis Murphy
m > >>> -Original Message- >>> From: roslina...@gmail.com >>> Sent: Fri, 5 Jun 2015 16:49:08 +0800 >>> To: r-help@r-project.org >>> Subject: [R] if else statement for rain data to define zero for dry and >>> one to wet >>> &

Re: [R] if else statement for rain data to define zero for dry and one to wet

2015-06-06 Thread roslinazairimah zakaria
;-ifelse(x[,column]>=thresh,1,0) > return(x) > } > wet_dry(dt) > > and see what you get. > > Also, why can I read your message perfectly while everybody else can't? > > Jim > > >> -Original Message- > >> From: roslina...@gmail.com > >>

Re: [R] if else statement for rain data to define zero for dry and one to wet

2015-06-06 Thread Jim Lemon
I read your message perfectly while everybody else can't? Jim >> -Original Message- >> From: roslina...@gmail.com >> Sent: Fri, 5 Jun 2015 16:49:08 +0800 >> To: r-help@r-project.org >> Subject: [R] if else statement for rain data to define zero for dry

Re: [R] if else statement for rain data to define zero for dry and one to wet

2015-06-05 Thread John Kane
/Reproducibility.html for some suggestions on how to post to R-help. John Kane Kingston ON Canada > -Original Message- > From: roslina...@gmail.com > Sent: Fri, 5 Jun 2015 16:49:08 +0800 > To: r-help@r-project.org > Subject: [R] if else statement for rain data to define zero for d

Re: [R] if else statement for rain data to define zero for dry and one to wet

2015-06-05 Thread PIKAL Petr
AM > To: r-help@r-project.org > Subject: [R] if else statement for rain data to define zero for dry and > one to wet > > Dear r-users, > > I have a set of rain data: > > X1950 X1951 X1952 X1953 X1954 X1955 X1956 X1957 X1958 X1959 X1960 X1961 > X1962 > > 1 0.0 0.0

[R] if else statement for rain data to define zero for dry and one to wet

2015-06-05 Thread roslinazairimah zakaria
Dear r-users, I have a set of rain data: X1950 X1951 X1952 X1953 X1954 X1955 X1956 X1957 X1958 X1959 X1960 X1961 X1962 1 0.0 0.0 14.3 0.0 13.5 13.2 4.0 0 3.3 0 0 0.0 2 0.0 0.0 21.9 0.0 10.9 6.6 2.1 0 0.0 0 0 0.0 3 25.3 6.7 18.6 0.8

Re: [R] if else for cumulative sum error

2014-12-03 Thread Jefferson Ferreira-Ferreira
ogy > Texas A&M University > College Station, TX 77840-4352 > > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David > Winsemius > Sent: Tuesday, December 2, 2014 2:50 PM > To: Jefferson Ferreira-Ferreira > Cc: r-help

Re: [R] if else for cumulative sum error

2014-12-02 Thread David L Carlson
ege Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius Sent: Tuesday, December 2, 2014 2:50 PM To: Jefferson Ferreira-Ferreira Cc: r-help@r-project.org Subject: Re: [R] if else for cumulative sum error On Dec 2, 2014, at 12:26 PM

Re: [R] if else for cumulative sum error

2014-12-02 Thread David Winsemius
On Dec 2, 2014, at 12:26 PM, Jefferson Ferreira-Ferreira wrote: > Thank you for replies. > > David, > > I tried your modified form > > for (i in 1:seq_along(rownames(dadosmax))){ No. it is either 1: or seq_along(...). in this case perhaps 1:(nrow(dadosmax)-44 would be safer You do not

Re: [R] if else for cumulative sum error

2014-12-02 Thread Jefferson Ferreira-Ferreira
Thank you for replies. David, I tried your modified form for (i in 1:seq_along(rownames(dadosmax))){ dadosmax$enchday[i] <- if ( (sum(dadosmax$above[i:(i+44)])) >= 45) 1 else 0 } However, I'm receiving this warning: Warning message: In 1:seq_along(rownames(dadosmax)) : numerical expression

Re: [R] if else for cumulative sum error

2014-12-02 Thread John McKown
On Tue, Dec 2, 2014 at 12:08 PM, Jefferson Ferreira-Ferreira < jeco...@gmail.com> wrote: > Hello everybody; > > I'm writing a code where part of it is as follows: > > for (i in nrow(dadosmax)){ > dadosmax$enchday[i] <- if (sum(dadosmax$above[i:(i+44)]) >= 45) 1 else 0 > } > ​Without some test d

Re: [R] if else for cumulative sum error

2014-12-02 Thread David Winsemius
On Dec 2, 2014, at 10:08 AM, Jefferson Ferreira-Ferreira wrote: > Hello everybody; > > I'm writing a code where part of it is as follows: > > for (i in nrow(dadosmax)){ > dadosmax$enchday[i] <- if (sum(dadosmax$above[i:(i+44)]) >= 45) 1 else 0 > } > > That is for each row of my data frame, su

[R] if else for cumulative sum error

2014-12-02 Thread Jefferson Ferreira-Ferreira
Hello everybody; I'm writing a code where part of it is as follows: for (i in nrow(dadosmax)){ dadosmax$enchday[i] <- if (sum(dadosmax$above[i:(i+44)]) >= 45) 1 else 0 } That is for each row of my data frame, sum an specific column (0 or 1) of that row plus 44 rows. If It is >=45 than enchday

Re: [R] if else statement in loop

2014-09-29 Thread PIKAL Petr
e(1:3, .Label = c("samas4", "samas5", "samas6" ), class = "factor")), .Names = c("FID", "IID"), class = "data.frame", row.names = c(NA, -3L)) > -Original Message- > From: Kate Ignatius [mailto:kate.ignat...@g

Re: [R] if else statement in loop

2014-09-29 Thread Kate Ignatius
is column X$IID1new != '' does not exist in X > > Here you clearly ask for nonexistent column, and why the heck you want to > select column by number of rows? > >> as.character(as.matrix(X[,(2*nrow(X)+1)])) > Error in `[.data.frame`(X, , (2 * nrow(X) + 1)) : >

Re: [R] if else statement in loop

2014-09-28 Thread PIKAL Petr
2 * nrow(X) + 1)) : undefined columns selected So based on your toy data frames, what shall be the result after your computation. Regards Petr > -Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Kate Ignatius > Se

[R] if else statement in loop

2014-09-28 Thread Kate Ignatius
I have two data frames For simplicity: X= V1 V2 V3 V4 V5 V6 samas4 samas5 samas6 samas4_father samas5_mother samas6_sibling samas4 samas5 samas6 samas4_father samas5_mother samas6_sibling samas4 samas5 samas6 samas4_father samas5_mother samas6_sibling Y= FID IID FAM01 samas4 FAM01 samas5 FAM0

Re: [R] if else in R

2013-11-19 Thread David Winsemius
On Nov 19, 2013, at 5:30 PM, Gary Dong wrote: > Dear R users, > > I am a R beginner and I am having trouble in using "If Else" in R. Here is > an example: > > ## create a data frame > > a<-c(1,2,3,4) > b<-c(2,0,5,0) > ab<-data.frame(cbind(a,b)) > > ##calculate c, which is the ratio between a

Re: [R] if else in R

2013-11-19 Thread Jeff Newmiller
Which means you should use the ifelse function... ab$c <- ifelse( ab$b>0, ab$a/ab$b, 0 ) --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go...

Re: [R] if else in R

2013-11-19 Thread arun
Hi, Try: within(ab, {c <- ifelse(b>0, a/b,0)}) A.K. On Tuesday, November 19, 2013 8:51 PM, Gary Dong wrote: Dear R users, I am a R beginner and I am having trouble in using "If Else" in R. Here is an example: ## create a data frame a<-c(1,2,3,4) b<-c(2,0,5,0) ab<-data.frame(cbind(a,b)) ##c

Re: [R] if else in R

2013-11-19 Thread Ben Tupper
Hi, On Nov 19, 2013, at 9:41 PM, Nick Matzke wrote: > Hi, > > This would be an issue with if() as well as if/else. ab$b has 4 > numbers in it, so ab$b > 0 evaluates to "TRUE TRUE FALSE TRUE" or > whatever. if() can only take a single true or false. Cheers! Nick > As a follow up, you could ma

Re: [R] if else in R

2013-11-19 Thread Nick Matzke
Hi, This would be an issue with if() as well as if/else. ab$b has 4 numbers in it, so ab$b > 0 evaluates to "TRUE TRUE FALSE TRUE" or whatever. if() can only take a single true or false. Cheers! Nick On Tue, Nov 19, 2013 at 8:30 PM, Gary Dong wrote: > Dear R users, > > I am a R beginner and I a

[R] if else in R

2013-11-19 Thread Gary Dong
Dear R users, I am a R beginner and I am having trouble in using "If Else" in R. Here is an example: ## create a data frame a<-c(1,2,3,4) b<-c(2,0,5,0) ab<-data.frame(cbind(a,b)) ##calculate c, which is the ratio between a and b if(ab$b>0) { ab$c<-ab$a/ab$b } else { ab$c<-0 } here is the e

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-26 Thread arun
y by: dat1$t.tr<- as.character(dat1$t.tr) A.K. - Original Message - From: "Fethe, Michael" To: Dennis Murphy ; "R-help@r-project.org" Cc: Sent: Monday, August 26, 2013 8:45 AM Subject: Re: [R] If else loop problem: the condition has length > 1 and only

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-26 Thread Fethe, Michael
689 -43.47 645.53 > #4 Pto 72 624 -68.17 555.83 > #5 Pto 72 666 -68.17 597.83 > #6 Pto 24 620 -29.39 590.61 > > > #or ?merge() > > A.K. > > > > > - Original Message - > From: Bert Gunter > To: arun > Cc: &q

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-26 Thread Fethe, Michael
a-j)? This code produces : In Ops.factor(signal2, 10.465507) : - not meaningful for factors Thanks for the input. ________ From: Dennis Murphy Sent: Monday, August 26, 2013 4:59 AM To: Fethe, Michael Subject: Re: [R] If else loop problem: the condition has length > 1 and

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-26 Thread PIKAL Petr
nces@r- > project.org] On Behalf Of arun > Sent: Monday, August 26, 2013 8:32 AM > To: Fethe, Michael > Cc: R help > Subject: Re: [R] If else loop problem: the condition has length > 1 and > only the first element will be used > > HI, > > It may be better to provide

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-26 Thread arun
Cc: "Fethe, Michael" ; R help Sent: Monday, August 26, 2013 10:09 AM Subject: Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used Suggestion: Don't do the ifelse stuff below. See ?switch  instead. -- Bert On Sun, Aug 25, 2013 at 1

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-26 Thread Bert Gunter
st 24", signal2-17.29, ifelse(t.tr=="Pst 48", > signal2 - 43.93256, etc.)) > > > A.K. > > - Original Message - > From: "Fethe, Michael" > To: "r-help@r-project.org" > Cc: > Sent: Sunday, August 25, 2013 9:31 PM > Subj

Re: [R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-25 Thread arun
"r-help@r-project.org" Cc: Sent: Sunday, August 25, 2013 9:31 PM Subject: [R] If else loop problem: the condition has length > 1 and only the first element will be used Hi all, I'm running an if else loop to normalize my data to a known control. I have calculated values that

[R] If else loop problem: the condition has length > 1 and only the first element will be used

2013-08-25 Thread Fethe, Michael
Hi all, I'm running an if else loop to normalize my data to a known control. I have calculated values that need to be subtracted from each treatment applied. I'm trying this within a for loop with if and else commands to apply to correct subtraction. This is done as follows: attach(data.2013)

Re: [R] if else elseif for data frames

2012-08-14 Thread PIKAL Petr
> > 2 highH > > 3 highH > > 4 NeutralN > > 5 NeutralN > > 6 NeutralN > > 7 lowL > > 8 lowL > > 9 lowL > > 10 lowL > > > > A.K. > > > > > > > >

Re: [R] if else elseif for data frames

2012-08-13 Thread Rolf Turner
lowL A.K. - Original Message ----- From: Sachinthaka Abeywardana To: r-help@r-project.org Cc: Sent: Sunday, August 12, 2012 8:43 PM Subject: [R] if else elseif for data frames Hi all, It seems like I cannot use normal 'if' for data frames. What would be the best way to do t

Re: [R] if else elseif for data frames

2012-08-13 Thread arun
ot;low"="L"') dat2 #  col1 col2 #1 high    H #2  Neutral    N #3  Neutral    N #4  low    L #5 high    H #6  low    L #7  low    L #8  Neutral    N #9  Neutral    N #10    high    H A.K. ________ From: Sachinthaka Abeywardana To:

Re: [R] if else elseif for data frames

2012-08-13 Thread arun
_ From: Sachinthaka Abeywardana To: arun Cc: R help Sent: Sunday, August 12, 2012 9:07 PM Subject: Re: [R] if else elseif for data frames The thing is I have about 10 cases. I saw the ifelse statement but was wondering if there was a cleaner method of doing it. The coding will get re

Re: [R] if else elseif for data frames

2012-08-12 Thread R. Michael Weylandt
On Sun, Aug 12, 2012 at 8:07 PM, Sachinthaka Abeywardana wrote: > The thing is I have about 10 cases. I saw the ifelse statement Note that there is no "ifelse" statement: there is only nested if/else of forms if else if else if else > but was > wondering if

Re: [R] if else elseif for data frames

2012-08-12 Thread David Winsemius
On Aug 12, 2012, at 5:43 PM, Sachinthaka Abeywardana wrote: Hi all, It seems like I cannot use normal 'if' for data frames. What would be the best way to do the following. if data$col1='high' data$col2='H' else if data$col1='Neutral' data$col2='N' else if data$col='low' data$col2='

Re: [R] if else elseif for data frames

2012-08-12 Thread Jeff Newmiller
; dat1 >>> col1 col2 >>> 1 highH >>> 2 highH >>> 3 highH >>> 4 NeutralN >>> 5 NeutralN >>> 6 NeutralN >>> 7 lowL >>> 8 lowL >>> 9 lowL >

Re: [R] if else elseif for data frames

2012-08-12 Thread jim holtman
H >> 4 NeutralN >> 5 NeutralN >> 6 NeutralN >> 7 low L >> 8 lowL >> 9 lowL >> 10 lowL >> >> A.K. >> >> >> >> >> - Original Message - >> From: Sachi

Re: [R] if else elseif for data frames

2012-08-12 Thread arun
2 1 high    H 2 high    H 3 high    H 4  Neutral    N 5  Neutral    N 6  Neutral    N 7  low    L 8  low    L 9  low    L 10 low    L A.K. - Original Message - From: Sachinthaka Abeywardana To: r-help@r-project.org Cc: Sent: Sunday, August 12, 2012 8:43 PM

Re: [R] if else elseif for data frames

2012-08-12 Thread Sachinthaka Abeywardana
highH > 2 highH > 3 highH > 4 NeutralN > 5 NeutralN > 6 NeutralN > 7 lowL > 8 lowL > 9 lowL > 10 lowL > > A.K. > > > > > - Original Message - > From: Sachinthaka Abey

[R] if else elseif for data frames

2012-08-12 Thread Sachinthaka Abeywardana
Hi all, It seems like I cannot use normal 'if' for data frames. What would be the best way to do the following. if data$col1='high' data$col2='H' else if data$col1='Neutral' data$col2='N' else if data$col='low' data$col2='L' else #chuch a warning? Note that col2 was not an existin

Re: [R] if/else statement without curly brackets gives a problem

2012-01-21 Thread Florent D.
It is well explained here http://www.burns-stat.com/pages/Tutor/R_inferno.pdf page 67. On Sat, Jan 21, 2012 at 9:56 PM, Ery Arias-Castro wrote: > Hello, > > This example seems strange to me: > > > if (2 > 3) print('Yes'); else print('No') > Error: unexpected 'else' in " else" > > > {if (2 > 3) p

  1   2   >