Hi,
May be this helps.
dat1<- read.table(text="
Col1,Col2
High value,9
Low value,0
High value,7
Low value,0
Low value,0
No data,0
High value,8
No data,0
",sep=",",header=TRUE,stringsAsFactors=FALSE)
dat1$Col2[dat1$Col1=="No data"]<- NA
dat1
# Col1 Col2
#1 High value 9
#2 Low value
(relativenes[i] < cost) {dispersal[i]
<-((relativenes[i]- cost)/(relativenes[i]- cost*cost))} else
{dispersal[i] <- 0}}
}
}
> Subject: Re: [R] If function error: missing value where TRUE/FALSE needed
> From: petr.pi...@prech
which is treated by if as an inappropriate input so there is
missing value error.
But without data and its structure it is only a guess.
Regards
Petr
>
> [R] If function error: missing value where TRUE/FALSE needed
>
>
> Hello!
> I am trying to get a logic estatement in
Hello!
I am trying to get a logic estatement in R using the if function, but it is all
the time comming and error, I have tryied different methods but nothing is
working
the sentence is the following:
dispersal[1] <- if (any (relativenes[1] < cost)) ((relativenes[1]-
cost)/(relativenes[1]- co
Thank you for your adding, Steve, i followed Daivd's suggection and finally
got the answer.
It is my careless that should put lena instead of lenx.
I also tried your codes and worked well. I appreciate your help. I learnt a
lot from this forum.
Cheers,
Zoe
--
View this message in context:
http:/
Hi
another possibility is to use logical values properties
> (x < 0)*x
[1] -3 -2 -1 0 0 0 0
Regards
Petr
>
> In addition to what David said:
>
> On Mon, Aug 1, 2011 at 6:57 PM, zoe_zhang <1987.zhan...@gmail.com>
wrote:
> > Dear All,
> > Sorry to bother
> > I want to write a function in R
David, I'm so appreciate!
Sincerely,
Zoe
--
View this message in context:
http://r.789695.n4.nabble.com/if-function-problems-tp3710995p3711062.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://s
In addition to what David said:
On Mon, Aug 1, 2011 at 6:57 PM, zoe_zhang <1987.zhan...@gmail.com> wrote:
> Dear All,
> Sorry to bother
> I want to write a function in R using if
> Say I have a dataset x,
> if x[i]<0, then x[i]=x[i],
> if x[i]>0, then x[i]=0
>
> for example, x=-3:3,
> then using t
On Aug 1, 2011, at 6:57 PM, zoe_zhang wrote:
Dear All,
Sorry to bother
I want to write a function in R using if
Say I have a dataset x,
if x[i]<0, then x[i]=x[i],
if x[i]>0, then x[i]=0
for example, x=-3:3,
then using the function, x becomes [-3,-2,-1,0,0,0,0]
Just use logical indexing
x[ x>
Dear All,
Sorry to bother
I want to write a function in R using if
Say I have a dataset x,
if x[i]<0, then x[i]=x[i],
if x[i]>0, then x[i]=0
for example, x=-3:3,
then using the function, x becomes [-3,-2,-1,0,0,0,0]
I write the codes as follows,
gjr=function(x)
{lena=length(x)
for(i in 1:lenx)
10 matches
Mail list logo