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 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 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 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

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

2012-01-21 Thread jim holtman
Don't use the ';' > if (2 > 3) print('Yes'); else print('No') Error: unexpected 'else' in " else" No suitable frames for recover() > if (2 > 3) print('Yes') else print('No') [1] "No" > 'else' is part of the 'if'. The ';' implies the start of a new statement. You do not need the ';' when writing

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

2012-01-21 Thread Ery Arias-Castro
Hello, This example seems strange to me: > if (2 > 3) print('Yes'); else print('No') Error: unexpected 'else' in " else" > {if (2 > 3) print('Yes'); else print('No')} Error: unexpected 'else' in "{if (2 > 3) print('Yes'); else" > { + if (2 > 3) print('no') + else print('yes') + } [1

Re: [R] if else statement error

2009-10-03 Thread Duncan Murdoch
On 03/10/2009 3:33 PM, Marianne Promberger wrote: Two problems with your code: (1) The "else" has to be on the same line as the closing "}" -- this was confusing for me as well. (2) "and" probably should be "&", but read up on logical operators: ?& Better to always use && in an if. Duncan M

Re: [R] if else statement error

2009-10-03 Thread Marianne Promberger
Two problems with your code: (1) The "else" has to be on the same line as the closing "}" -- this was confusing for me as well. (2) "and" probably should be "&", but read up on logical operators: ?& Try: ini=3 b=4 if (ini==1) { a=3 } else if (ini>1 & b>2 ) { a=3 } else { a=6 } HTH, Ma

[R] if else statement error

2009-10-03 Thread gcheer3
Hello, I am doing a if else statement in R. But it always comes out error such as 'unexpected symbol' There are two variables. ini and b. when ini=1, a=3; when ini>1 and b>2, a=3; all other situations, a=6. I don't know where it is wrong. Here is my code ini=3 b=4 if (ini==1) { a=3