Displaying 1 result from an estimated 1 matches for "nupul".
Did you mean:
upul
2005 Nov 10
7
different functions on different vector subsets
...like to raise it by the power of 2: 2^a and if the a<0 I
would like to have the inverse value, i.e., -1/2^a.
so I thought of doing it two steps:
a[a>0]<-2^[a>0]
a[a<0]<-(-1)/2^a[a<0]
I got the following error
Error: NAs are not allowed in subscripted assignments
any other ma>nupulation that I did with is.na() but did not succeed.
What is funny that the two sides of the assignment work and return the
same vector size:
> 2^a[a>0]
[1] NA 2 4 8
> a[a>0]
[1] NA 1 2 3
I found a solution in term of:
sapply(a,function(x) if (is(s.na)) NA else if (x<0) (-1)/2^x...