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 '
?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
À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?
___
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
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
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
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
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
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
>
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
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
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,
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
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
>
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
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
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
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
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
>
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
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
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
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
"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
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
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,
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
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
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
> 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
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
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
> 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
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
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
> 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
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
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
>
> 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
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
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
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
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
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
>>>>> 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
on sex and it is blank.
> >>> > id sex
> >>> > 1
> >>> > 2
> >>> > 3 M
> >>> > 4 F
> >>> > 5 M
> >>> > 6 F
> >>> > 7 F
> >>&g
F
>>> >
>>> >I am reading the data like this
>>> >
>>> >mydata <- read.csv(header=TRUE, text=', sep=", ")
>>> > id sex
>>> > 1 NA
>>> > 2 NA
>>> > 3 M
>>
>> > 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
>> &
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
> >>
> >>
> >> > -
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:
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
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
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
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
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=
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
; > 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
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
>>>
&
;-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
> >>
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
/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
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
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
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
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
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
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
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
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
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
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
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)) :
>
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
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
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
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...
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
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
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
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
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
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
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
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
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
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
"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
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)
> > 2 highH
> > 3 highH
> > 4 NeutralN
> > 5 NeutralN
> > 6 NeutralN
> > 7 lowL
> > 8 lowL
> > 9 lowL
> > 10 lowL
> >
> > A.K.
> >
> >
> >
> >
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
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:
_
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
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
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='
; dat1
>>> col1 col2
>>> 1 highH
>>> 2 highH
>>> 3 highH
>>> 4 NeutralN
>>> 5 NeutralN
>>> 6 NeutralN
>>> 7 lowL
>>> 8 lowL
>>> 9 lowL
>
H
>> 4 NeutralN
>> 5 NeutralN
>> 6 NeutralN
>> 7 low L
>> 8 lowL
>> 9 lowL
>> 10 lowL
>>
>> A.K.
>>
>>
>>
>>
>> - Original Message -
>> From: Sachi
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
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
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
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 - 100 of 156 matches
Mail list logo