Displaying 20 results from an estimated 20000 matches similar to: "a strange behavior with ifelse"
2008 Feb 12
2
how to specify modes of certain fields in read.table
I have a data file with 50 columns. Among them, there are two
coordinates, X and Y
X
Y
641673.78807
3607080.78438
641436.56207
3607108.30543
641165.28042
3607136.82957
640879.58373
3607116.20568
When I use read.table, it rounds X and Y to the maximal 8 decimal number
as.
641673.8 3607081
641436.6 3607108
641165.3 3607137
640879.6 3607116
640683.5 3607105
My question
2008 Feb 11
2
how to generate a column based on other columns in a data frame
HI,
I am working on a data set with multiple collections of mosquitoes at
sampling sites. Each row represents a collection of individual samples
with coordinates for each collection.
... X, Y,...
1 36.435 30.118
2 36.435 30.118
3 36.435 30.118
4 35.329 29.657
5 35.329 29.657
6 36.431 30.111
7 36.431 30.111
8 35.421 29.797
9 35.421 29.797
10 35.421 29.797
2008 Feb 08
4
how to extract characters from a character string
Hi, I ran into a problem when I complied a dataset with UTM coordinates.
For calculating distances between sites, I need to reformat the
coordinates from, for example,
32?35.421 N, to 35.421, i.e. I need to delete all digits before symbol ?
and a space and N at the end of the string. What functions I should use?
Thanks in advance.
Weidong Gu,
Department of Medicine
University of
2002 Sep 02
2
ifelse behavior
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Dear R-Users,
I cannot understand the behavior of ifelse.
I have a vector blah
> str(blah)
List of 14
$ index.s : num 100
$ index.u : num 100
$ index.t : num 100
$ yabstand.s: num NA
$ yabstand.u: num NA
$ modal.s : int 8
$ modal.u : int 71
$ modal.t : int 21
>
> str(blah$index.s)
num 100
>
everything seems OK.
when
2010 Aug 20
1
strange behavior of ifelse with factors
Dear R experts: this is probably correct behavior, but I do want to
point out that it is unexpected to someone not too well versed:
> test=factor("A","B","C","A")
> ifelse(test=="A", as.factor("A"), test)
[1] 1 2 3 1
ok, my factor was just coerced into integers, even though I have a
logical vector as my condition and factors as
2008 Jan 07
1
How to rearrange lattice graphics output?
My question arises when I use levelplot graphics. For example,
levelplot(z~x*y|fg) where fg is a factor with three levels of
'a','b','c'. The panels come out in a default order. I would like to
rearrange the panels in a manner of 'c','b','a'. I used
fg<-ordered(fg, levels=c('c','b','a'))
But the panels are still the
2006 Nov 21
2
using nested ifelse and rowSums to create new variable?
Dear R-help community,
If I have a data.frame df as follows:
> df
x1 x2 x3 x4 x5 x6
1 5 5 1 1 2 1
2 5 5 5 5 1 5
3 1 5 5 5 5 5
4 5 5 1 4 5 5
5 5 1 5 2 4 1
6 5 1 5 4 5 1
7 5 1 5 4 4 5
8 5 1 1 1 1 5
9 1 5 1 1 2 5
10 5 1 5 4 5 5
11 1 5 5 2 1 1
12 5 5 5 4 4 1
13 1 5 1 4 4 1
14 1 1 5 4 5 5
15 1 5 5 4
2010 Mar 10
1
ifelse logic and multiple assignments
I'm a fairly new R user and while I have a solution to my problem I'm
wondering if there is a better one.
In SAS it's common to use if/then logic along with a "do" statement to
make several things happen. While I could do the same thing in R
using a "for" loop, and "if" and {}, I've read that loops are less
common in R and I wonder if I'm doing
2016 Nov 27
1
ifelse() woes ... can we agree on a ifelse2() ?
Related to the length of 'ifelse' result, I want to say that "example of different return modes" in ?ifelse led me to perceive a wrong thing in the past.
## example of different return modes:
yes <- 1:3
no <- pi^(0:3)
typeof(ifelse(NA, yes, no)) # logical
typeof(ifelse(TRUE, yes, no)) # integer
typeof(ifelse(FALSE, yes, no)) # double
As
2005 Jun 22
2
Trouble with ifelse and if statement (PR#7962)
Full_Name: Woolton Lee
Version: 2.1
OS: windows
Submission from: (NULL) (128.118.224.46)
I did the following ('g' and 'h' are both numeric vectors)
> i <- abs(g-h)
creating a vector 'i' with values,
> i
[1] 0.08 0.00 0.33 0.00 0.00 0.00 0.00 0.33 0.00 0.00 0.08 0.08 0.20 0.00 0.13
Now, I want to create a new vector =1 whenever 'i' = 0.33 and =0
2008 Sep 07
1
run optim() on a list
Hi,
I am at the end of my wit to figure out how to run the optim function on
a list.
Basically, I have a data set of three columns as "Site", "Pool" and
"Positivity" ( the full data set is copied at the end). I want to run
the maximal likelihood estimation separately on subsets split by "Site"
data<-read.table(...)
2005 Jun 01
2
A suggestion to improve ifelse behaviour with vector yes/noarguments
> Thomas Lumley wrote:
> > On Tue, 31 May 2005, Duncan Murdoch wrote:
> >
> >
> >>M??kinen Jussi wrote:
> >>
> >>>Dear All,
> >>>
> >>>I luckily found the following feature (or problem) when tried to
> >>>apply
> >>>ifelse-function to an ordered data.
> >>>
> >>>
>
2009 Oct 24
2
ifelse
When I run this code from an R-script:
ddd = 360 + round ( atan2(-u,-v) / d2r )
print(class(ddd))
print(ddd)
ifelse ( ddd>360, ddd-360, ddd )
print(ddd)
I get this output:
[1] "numeric"
[1] 461 213 238 249 251
[1] 461 213 238 249 251
Why does ifelse not change the 461 to 101?
I recreated the vector ddd and ran the same ifelse
code
2009 Feb 13
2
extracting parts of words or extraxting letter to use in ifelse-func.
Hello
I want to make some variables with the ifelse-function, but i don't know how
to do it.
I want to make these five variables;
b2$PRRSvac <- ifelse(b2$status=='A' | b2$status=='Aa',1,0)
b2$PRRSdk <- ifelse(b2$status=='B' | b2$status=='Bb',1,0)
b2$sanVac <- ifelse(b2$status=='C' | b2$status=='sanAa',1,0)
b2$sanDk <-
2018 May 03
1
Proposed speedup of ifelse
I propose a patch to ifelse that leverages anyNA(test) to achieve an
improvement in performance. For a test vector of length 10, the change
nearly halves the time taken and for a test of length 1 million, there
is a tenfold increase in speed. Even for small vectors, the
distributions of timings between the old and the proposed ifelse do
not intersect.
The patch does not intend to change the
2007 Dec 20
1
ifelse problem
Could someone help me with the following code snippet. The results are not
what I expect:
> Sheet1$Claims[1:10]
[1] NA 1 2 NA NA NA NA NA NA NA
> Sheet1[1:10,"SubmissionStatus"]
[1] Declined Bound Bound Bound Bound Bound Declined
Dead Declined
[10] Not Taken
Levels: Bound Dead Declined Not Taken
> Sheet1$Claimsnum <- NA
>
2008 Aug 27
1
ifelse() fill order and recycling rules [Sec=Unclassified]
Hi all,
Using R v2.7.1, platform i386-pc-mingw32
Can someone please shed some light on the behaviour of ifelse() for me?
My intent is to calc relative proportions of z$b, at the same time
subsetting z$b based on z$a. I could attack the problem other ways
(suggestions welcome) but I am also intrigued by the _order_ in which
ifelse seems to assign values, and how recycling works. For instance,
2010 Mar 17
2
How to use "ifelse" to generate random value from a distribution
I need use different parameters of distribution for different case to
generate random value, but I use ifelse, the generated value is fixed
without change.
Here is example
data1
y x
1 1 2
2 2 1
3 3 2
4 4 3
5 5 3
6 6 1
7 7 2
8 8 1
9 9 1
10 10 3
11 11 3
12 12 2
ifelse(data1$x==1,rnorm(1,2,1),ifelse(data1$x==2,rnorm(1,-2,1),rnorm(1,110,1)))
[1] -1.8042172 0.8478681
2010 Feb 23
3
Use 2 "ifelse" to sort data
Dear R users,
I have a question how to use 2 "ifelse" to sort my data. Such as
from 11 to 20 assign to A; 6 to 10 assign to B, and the rest of them assign
to C
a<-1:20
tt<-ifelse(a>10, "A",no=ifelse( 5< a <=10, "B", "C"))
Many Thanks
Chunhao
--
View this message in context:
2012 Jan 19
3
Establishing groups using something other than ifelse()
Hello all,
This is one of those "Is there a better way to do this questions". Say
I have a dataframe (df) with a grouping variable (z). This is my base
data. Now I know that there is a higher order level of grouping that
exist for my group variable. So what I want to do is create a new
column that express that higher order level of grouping based on
values in the sub-group (z in this