Bodnar Laszlo EB_HU
2011-Feb-10 14:07 UTC
[R] help - "the condition has length > 1 and only the first element will be used"
Hello there,
I don't know if I'm addressing my question to the right e-mail address,
I hope I do. Actually I have a little problem concerning writing a code in R. I
try to briefly sum up my problem.
As you can see below, I created the functions "Equation1" and
"Equation2" with some conditions.
Equation1 <-function(x){
if (x<=0.25) y <-1-4*x
if (x>0.25) y <-0
y
}
Equation2 <-function(x){
if (x<=0.25) y <-4*x
if (x>0.25 & x<=0.5) y <-2-4*x
if (x>0.5) y <-0
y
}
And then I generated a sequence of numbers from 0 to 1 using the following
code:
x <-seq(0,1,0.05)
What I intended to do was to create 3 columns like below. In the first
column you can find all the x values I created just before using the seq
procedure and in the next 2 columns you can see all the calculated values of
functions Equation1 and Equation2 respectively.
x Egyenlet1 Egyenlet2
0.00 1.00 0.00
0.05 0.80 0.20
0.10 0.60 0.40
0.15 0.40 0.60
0.20 0.20 0.80
0.25 0.00 1.00
0.30 0.00 0.80
0.35 0.00 0.60
0.40 0.00 0.40
0.45 0.00 0.20
0.50 0.00 0.00
0.55 0.00 0.00
0.60 0.00 0.00
0.65 0.00 0.00
0.70 0.00 0.00
0.75 0.00 0.00
0.80 0.00 0.00
0.85 0.00 0.00
0.90 0.00 0.00
0.95 0.00 0.00
1.00 0.00 0.00
Unfortunately I didn't know how to create these columns. Whenever I
tried to send the following codes into R:
"Equation1(x)" or "Equation1(x)" (remember x
representing the values from 0 to 1)
...I instantaneously got a warning message saying:
[1] 1.0 0.8 0.6 0.4 0.2 0.0 -0.2 -0.4 -0.6 -0.8 -1.0 -1.2 -1.4 -1.6
-1.8 -2.0 -2.2 -2.4 -2.6 -2.8 -3.0
Warning messages:
1: In if (x <= 0.25) y <- 1 - 4 * x :
the condition has length > 1 and only the first element will be used
2: In if (x > 0.25) y <- 0 :
the condition has length > 1 and only the first element will be used
Could somebody please help me with this? I would greatly appreciate if
somebody would reply.
Thank you very much and have a pleasant day!
Best regards,
Laszlo
____________________________________________________________________________________________________
Ez az e-mail és az összes hozzá tartozó csatolt melléklet titkos és/vagy
jogilag, szakmailag vagy más módon védett információt tartalmazhat. Amennyiben
nem Ön a levél címzettje akkor a levél tartalmának közlése, reprodukálása,
másolása, vagy egyéb más úton történő terjesztése, felhasználása szigorúan
tilos. Amennyiben tévedésből kapta meg ezt az üzenetet kérjük azonnal értesítse
az üzenet küldőjét. Az Erste Bank Hungary Zrt. (EBH) nem vállal felelősséget az
információ teljes és pontos - címzett(ek)hez történő - eljuttatásáért, valamint
semmilyen késésért, kapcsolat megszakadásból eredő hibáért, vagy az információ
felhasználásából vagy annak megbízhatatlanságából eredő kárért.
Az üzenetek EBH-n kívüli küldője vagy címzettje tudomásul veszi és hozzájárul,
hogy az üzenetekhez más banki alkalmazott is hozzáférhet az EBH folytonos
munkamenetének biztosítása érdekében.
This e-mail and any attached files are confidential and/...{{dropped:19}}
Bodnar Laszlo EB_HU
2011-Feb-10 14:08 UTC
[R] help - "the condition has length > 1 and only the first element will be used"
Hello there,
I don't know if I'm addressing my question to the right e-mail address,
I hope I do. Actually I have a little problem concerning writing a code in R. I
try to briefly sum up my problem.
As you can see below, I created the functions "Equation1" and
"Equation2" with some conditions.
Equation1 <-function(x){
if (x<=0.25) y <-1-4*x
if (x>0.25) y <-0
y
}
Equation2 <-function(x){
if (x<=0.25) y <-4*x
if (x>0.25 & x<=0.5) y <-2-4*x
if (x>0.5) y <-0
y
}
And then I generated a sequence of numbers from 0 to 1 using the following
code:
x <-seq(0,1,0.05)
What I intended to do was to create 3 columns like below. In the first
column you can find all the x values I created just before using the seq
procedure and in the next 2 columns you can see all the calculated values of
functions Equation1 and Equation2 respectively.
x Egyenlet1 Egyenlet2
0.00 1.00 0.00
0.05 0.80 0.20
0.10 0.60 0.40
0.15 0.40 0.60
0.20 0.20 0.80
0.25 0.00 1.00
0.30 0.00 0.80
0.35 0.00 0.60
0.40 0.00 0.40
0.45 0.00 0.20
0.50 0.00 0.00
0.55 0.00 0.00
0.60 0.00 0.00
0.65 0.00 0.00
0.70 0.00 0.00
0.75 0.00 0.00
0.80 0.00 0.00
0.85 0.00 0.00
0.90 0.00 0.00
0.95 0.00 0.00
1.00 0.00 0.00
Unfortunately I didn't know how to create these columns. Whenever I
tried to send the following codes into R:
"Equation1(x)" or "Equation1(x)" (remember x
representing the values from 0 to 1)
...I instantaneously got a warning message saying:
[1] 1.0 0.8 0.6 0.4 0.2 0.0 -0.2 -0.4 -0.6 -0.8 -1.0 -1.2 -1.4 -1.6
-1.8 -2.0 -2.2 -2.4 -2.6 -2.8 -3.0
Warning messages:
1: In if (x <= 0.25) y <- 1 - 4 * x :
the condition has length > 1 and only the first element will be used
2: In if (x > 0.25) y <- 0 :
the condition has length > 1 and only the first element will be used
Could somebody please help me with this? I would greatly appreciate if
somebody would reply.
Thank you very much and have a pleasant day!
Best regards,
Laszlo
____________________________________________________________________________________________________
Ez az e-mail és az összes hozzá tartozó csatolt melléklet titkos és/vagy
jogilag, szakmailag vagy más módon védett információt tartalmazhat. Amennyiben
nem Ön a levél címzettje akkor a levél tartalmának közlése, reprodukálása,
másolása, vagy egyéb más úton történő terjesztése, felhasználása szigorúan
tilos. Amennyiben tévedésből kapta meg ezt az üzenetet kérjük azonnal értesítse
az üzenet küldőjét. Az Erste Bank Hungary Zrt. (EBH) nem vállal felelősséget az
információ teljes és pontos - címzett(ek)hez történő - eljuttatásáért, valamint
semmilyen késésért, kapcsolat megszakadásból eredő hibáért, vagy az információ
felhasználásából vagy annak megbízhatatlanságából eredő kárért.
Az üzenetek EBH-n kívüli küldője vagy címzettje tudomásul veszi és hozzájárul,
hogy az üzenetekhez más banki alkalmazott is hozzáférhet az EBH folytonos
munkamenetének biztosítása érdekében.
This e-mail and any attached files are confidential and/...{{dropped:19}}
Bodnar Laszlo EB_HU
2011-Feb-10 14:23 UTC
[R] help - "the condition has length > 1 and only the first element will be used"
Hi again!
I just wanted to say that during typing my message before I mistyped certain of
characters and I was just afraid that it might spoil the understanding of my
message. So I corrected the characters and now I'm sending you this
corrected letter again.
Terribly sorry for my mistake.
Thank you again,
Laszlo.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Hello there,
I don't know if I'm addressing my question to the right e-mail address,
I hope I do. Actually I have a little problem concerning writing a code in R. I
try to briefly sum up my problem.
As you can see below, I created the functions "Equation1" and
"Equation2" with some conditions.
Equation1 <-function(x){
if (x<=0.25) y <-1-4*x
if (x>0.25) y <-0
y
}
Equation2 <-function(x){
if (x<=0.25) y <-4*x
if (x>0.25 & x<=0.5) y <-2-4*x
if (x>0.5) y <-0
y
}
And then I generated a sequence of numbers from 0 to 1 using the following
code:
x <-seq(0,1,0.05)
What I intended to do was to create 3 columns like below. In the first
column you can find all the x values I created just before using the seq
procedure and in the next 2 columns you can see all the calculated values of
functions Equation1 and Equation2 respectively.
x Equation1 Equation2
0.00 1.00 0.00
0.05 0.80 0.20
0.10 0.60 0.40
0.15 0.40 0.60
0.20 0.20 0.80
0.25 0.00 1.00
0.30 0.00 0.80
0.35 0.00 0.60
0.40 0.00 0.40
0.45 0.00 0.20
0.50 0.00 0.00
0.55 0.00 0.00
0.60 0.00 0.00
0.65 0.00 0.00
0.70 0.00 0.00
0.75 0.00 0.00
0.80 0.00 0.00
0.85 0.00 0.00
0.90 0.00 0.00
0.95 0.00 0.00
1.00 0.00 0.00
Unfortunately I didn't know how to create these columns. Whenever I
tried to send the following codes into R:
"Equation1(x)" or "Equation2(x)" (remember x
representing the values from 0 to 1)
...I instantaneously got a warning message saying:
[1] 1.0 0.8 0.6 0.4 0.2 0.0 -0.2 -0.4 -0.6 -0.8 -1.0 -1.2 -1.4 -1.6
-1.8 -2.0 -2.2 -2.4 -2.6 -2.8 -3.0
Warning messages:
1: In if (x <= 0.25) y <- 1 - 4 * x :
the condition has length > 1 and only the first element will be used
2: In if (x > 0.25) y <- 0 :
the condition has length > 1 and only the first element will be used
Could somebody please help me with this? I would greatly appreciate if
somebody would reply.
Thank you very much and have a pleasant day!
Best regards,
Laszlo
____________________________________________________________________________________________________
Ez az e-mail és az összes hozzá tartozó csatolt melléklet titkos és/vagy
jogilag, szakmailag vagy más módon védett információt tartalmazhat. Amennyiben
nem Ön a levél címzettje akkor a levél tartalmának közlése, reprodukálása,
másolása, vagy egyéb más úton történő terjesztése, felhasználása szigorúan
tilos. Amennyiben tévedésből kapta meg ezt az üzenetet kérjük azonnal értesítse
az üzenet küldőjét. Az Erste Bank Hungary Zrt. (EBH) nem vállal felelősséget az
információ teljes és pontos - címzett(ek)hez történő - eljuttatásáért, valamint
semmilyen késésért, kapcsolat megszakadásból eredő hibáért, vagy az információ
felhasználásából vagy annak megbízhatatlanságából eredő kárért.
Az üzenetek EBH-n kívüli küldője vagy címzettje tudomásul veszi és hozzájárul,
hogy az üzenetekhez más banki alkalmazott is hozzáférhet az EBH folytonos
munkamenetének biztosítása érdekében.
This e-mail and any attached files are confidential and/...{{dropped:19}}
Jonathan P Daily
2011-Feb-10 15:39 UTC
[R] help - "the condition has length > 1 and only the first element will be used"
The issue here is that if only accepts a single True/False argument. Try
these functions:
?ifelse
?all
?any
--------------------------------------
Jonathan P. Daily
Technician - USGS Leetown Science Center
11649 Leetown Road
Kearneysville WV, 25430
(304) 724-4480
"Is the room still a room when its empty? Does the room,
the thing itself have purpose? Or do we, what's the word... imbue it."
- Jubal Early, Firefly
r-help-bounces at r-project.org wrote on 02/10/2011 09:07:40 AM:
> [image removed]
>
> [R] help - "the condition has length > 1 and only the first element
> will be used"
>
> Bodnar Laszlo EB_HU
>
> to:
>
> 'r-help at r-project.org'
>
> 02/10/2011 10:25 AM
>
> Sent by:
>
> r-help-bounces at r-project.org
>
> Hello there,
>
>
>
> I don't know if I'm addressing my question to the right e-mail
> address, I hope I do. Actually I have a little problem concerning
> writing a code in R. I try to briefly sum up my problem.
>
>
>
> As you can see below, I created the functions "Equation1" and
> "Equation2" with some conditions.
>
>
>
> Equation1 <-function(x){
>
> if (x<=0.25) y <-1-4*x
>
> if (x>0.25) y <-0
>
> y
>
> }
>
>
>
> Equation2 <-function(x){
>
> if (x<=0.25) y <-4*x
>
> if (x>0.25 & x<=0.5) y <-2-4*x
>
> if (x>0.5) y <-0
>
> y
>
> }
>
>
>
> And then I generated a sequence of numbers from 0 to 1 using
> the following code:
>
>
>
> x <-seq(0,1,0.05)
>
>
>
> What I intended to do was to create 3 columns like below. In
> the first column you can find all the x values I created just before
> using the seq procedure and in the next 2 columns you can see all
> the calculated values of functions Equation1 and Equation2 respectively.
>
>
>
> x Egyenlet1 Egyenlet2
>
> 0.00 1.00 0.00
>
> 0.05 0.80 0.20
>
> 0.10 0.60 0.40
>
> 0.15 0.40 0.60
>
> 0.20 0.20 0.80
>
> 0.25 0.00 1.00
>
> 0.30 0.00 0.80
>
> 0.35 0.00 0.60
>
> 0.40 0.00 0.40
>
> 0.45 0.00 0.20
>
> 0.50 0.00 0.00
>
> 0.55 0.00 0.00
>
> 0.60 0.00 0.00
>
> 0.65 0.00 0.00
>
> 0.70 0.00 0.00
>
> 0.75 0.00 0.00
>
> 0.80 0.00 0.00
>
> 0.85 0.00 0.00
>
> 0.90 0.00 0.00
>
> 0.95 0.00 0.00
>
> 1.00 0.00 0.00
>
>
>
> Unfortunately I didn't know how to create these columns.
> Whenever I tried to send the following codes into R:
>
> "Equation1(x)" or "Equation1(x)" (remember x
representing the
> values from 0 to 1)
>
> ...I instantaneously got a warning message saying:
>
>
>
> [1] 1.0 0.8 0.6 0.4 0.2 0.0 -0.2 -0.4 -0.6 -0.8 -1.0
> -1.2 -1.4 -1.6 -1.8 -2.0 -2.2 -2.4 -2.6 -2.8 -3.0
>
> Warning messages:
>
> 1: In if (x <= 0.25) y <- 1 - 4 * x :
>
> the condition has length > 1 and only the first element will be
used>
> 2: In if (x > 0.25) y <- 0 :
>
> the condition has length > 1 and only the first element will be
used>
>
>
> Could somebody please help me with this? I would greatly
> appreciate if somebody would reply.
>
> Thank you very much and have a pleasant day!
>
>
>
> Best regards,
>
> Laszlo
>
>
>
>
____________________________________________________________________________________________________>
> Ez az e-mail ??s az ??sszes hozz?? tartoz?? csatolt mell??klet
> titkos ??s/vagy jogilag, szakmailag vagy m??s m??don v??dett
> inform??ci??t tartalmazhat. Amennyiben nem ??n a lev??l c??mzettje
> akkor a lev??l tartalm??nak k??zl??se, reproduk??l??sa, m??sol??sa,
> vagy egy??b m??s ??ton t??rt??n?? terjeszt??se, felhaszn??l??sa
> szigor??an tilos. Amennyiben t??ved??sb??l kapta meg ezt az
> ??zenetet k??rj??k azonnal ??rtes??tse az ??zenet k??ld??j??t. Az
> Erste Bank Hungary Zrt. (EBH) nem v??llal felel??ss??get az
> inform??ci?? teljes ??s pontos - c??mzett(ek)hez t??rt??n?? -
> eljuttat??s????rt, valamint semmilyen k??s??s??rt, kapcsolat
> megszakad??sb??l ered?? hib????rt, vagy az inform??ci??
> felhaszn??l??s??b??l vagy annak megb??zhatatlans??g??b??l ered??
k??r??rt.>
>
>
> Az ??zenetek EBH-n k??v??li k??ld??je vagy c??mzettje tudom??sul
> veszi ??s hozz??j??rul, hogy az ??zenetekhez m??s banki alkalmazott
> is hozz??f??rhet az EBH folytonos munkamenet??nek biztos??t??sa
??rdek??ben.>
>
>
>
>
> This e-mail and any attached files are confidential
and/...{{dropped:19}}>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.