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-boun...@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@r-project.org' > > 02/10/2011 10:25 AM > > Sent by: > > r-help-boun...@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@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. ______________________________________________ R-help@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.