#Do
apply(y,1,print)
#Note the space that is inserted before the 1. If you insert this space in
your function
apply(y,1,function(x){x-unlist(x); if (!is.na(x[2]) x[2]=='2k'
!is.na(x[1]) x[1]==' 1') 1 else 0} )
#you get the result you expect.
#Also, note that your !is.na conditions are
Hi, I had a weird results from using apply(). Here is an simple example:
y-data.frame(list(a=c(1,NA),b=c('2k','0')))
y
a b
1 1 2k
2 NA 0
apply(y,1,function(x){x-unlist(x); if (!is.na(x[2]) x[2]=='2k'
!is.na(x[1]) x[1]=='1') 1 else 0} )
This should print 1 0 as output, as
On Aug 29, 2011, at 8:02 PM, array chip wrote:
Hi, I had a weird results from using apply(). Here is an simple
example:
y-data.frame(list(a=c(1,NA),b=c('2k','0')))
y
a b
1 1 2k
2 NA 0
apply(y,1,function(x){x-unlist(x);
That is quite unnecessary since apply coerces the
-project.org
Subject: [R] weird apply() behavior
Hi, I had a weird results from using apply(). Here is an simple example:
y-data.frame(list(a=c(1,NA),b=c('2k','0')))
y
a b
1 1 2k
2 NA 0
apply(y,1,function(x){x-unlist(x); if (!is.na(x[2]) x[2]=='2k'
!is.na(x[1]) x
On Aug 29, 2011, at 8:17 PM, David Winsemius wrote:
On Aug 29, 2011, at 8:02 PM, array chip wrote:
Hi, I had a weird results from using apply(). Here is an simple
example:
y-data.frame(list(a=c(1,NA),b=c('2k','0')))
y
a b
1 1 2k
2 NA 0
apply(y,1,function(x){x-unlist(x);
Thanks Bill and David!
John
- Original Message -
From: William Dunlap wdun...@tibco.com
To: array chip arrayprof...@yahoo.com; r-help@r-project.org
r-help@r-project.org
Cc:
Sent: Monday, August 29, 2011 5:21 PM
Subject: RE: [R] weird apply() behavior
apply() should come with a big
array chip:
Hi, I had a weird results from using apply().
Consider:
y-data.frame(list(a=c(1,NA), b=c('2k','0')))
do.call(args=y,
Vectorize(v=c(a,b),
function(a,b) if(is.na(z-b==2k a==1)) 0
else z+0))
Heikki Kaskelma
Munkkiniemi
-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of Heikki Kaskelma
Sent: Monday, August 29, 2011 6:13 PM
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] weird apply() behavior
array chip:
Hi, I had a weird results from using
8 matches
Mail list logo