Hi, can someone tell me what is wrong in this function:
ilecyfr=function(x){
if (x=0){
return(1)
} else {
k=0
while (abs(x)/10^k >0) {
k=k+1
} return(k)
}}
--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-tp4649082.html
Sent from the R help mailing list archive at Nabble.com.
Problem with
5 messages · Sarah Goslee, David Winsemius, Haszun
*
ilecyfr=function(x){
if (x=0){
return(1)
} else {
k=0
while (abs(x)/10^k >1) {
k=k+1
} return(k)
}}
--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-tp4649082p4649084.html
Sent from the R help mailing list archive at Nabble.com.
And your problem is? Please note that the test for equality is == while the preferred assignment operator is <- Beyond that, some statement of what you're trying to accomplish and an actual executable example would be useful. Sarah
On Fri, Nov 9, 2012 at 12:53 PM, Haszun <crazystef13 at tlen.pl> wrote:
*
ilecyfr=function(x){
if (x=0){
return(1)
} else {
k=0
while (abs(x)/10^k >1) {
k=k+1
} return(k)
}}
--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-tp4649082p4649084.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________ 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.
On Nov 9, 2012, at 9:52 AM, Haszun wrote:
Hi, can someone tell me what is wrong in this function:
ilecyfr=function(x){
if (x=0){
return(1)
} else {
k=0
while (abs(x)/10^k >0) {
k=k+1
} return(k)
}}
So if x == 0 (that's your first error and possibly a fatal one, but let's then leave it behind) and you then want the function to return 0. Otherwise you want to test whether abs(x)/10^0 is greater than 0 and then keep increasing k until .... abs(x)/10^k is no longer >0 and then return k?
David Winsemius, MD Alameda, CA, USA
Thanks for help, now its working. -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-tp4649082p4649161.html Sent from the R help mailing list archive at Nabble.com.