Thanks for the solution
On Tue, Jun 22, 2010 at 1:02 AM, Peter Ehlers wrote:
> On 2010-06-22 1:45, steven mosher wrote:
>
>> Hmm
>>
>>
>>> DF<-data.frame(name=rep(1:5,each=2),x1=rep("A",10),x2=seq(10,19,by=1),x3=rep(NA,10),x4=seq(20,29,by=1))
>> DF$x3[5]<-50
>> mask<-apply(sample,2,"%in%", ta
On 2010-06-22 1:45, steven mosher wrote:
Hmm
DF<-data.frame(name=rep(1:5,each=2),x1=rep("A",10),x2=seq(10,19,by=1),x3=rep(NA,10),x4=seq(20,29,by=1))
DF$x3[5]<-50
mask<-apply(sample,2,"%in%", target)
This is getting confusing. What's 'sample'?
What's 'target'? Probably what you original
OK
slight modification
DF<-data.frame(name=rep(1:5,each=2),x1=rep("A",10),x2=seq(10,19,by=1),x3=rep(NA,10),x4=seq(20,29,by=1))
DF$x3[5]<-50
targets<-c(11,12,13,16,19,50,27,24,22,26)
mask<-apply(DF[,3:5],2, "%in%" ,targets)
mask<-!mask
DF[,3:5][mask]<-NA
DF
name x1 x2 x3 x4
1 1 A NA NA NA
Hmm
>
DF<-data.frame(name=rep(1:5,each=2),x1=rep("A",10),x2=seq(10,19,by=1),x3=rep(NA,10),x4=seq(20,29,by=1))
DF$x3[5]<-50
mask<-apply(sample,2,"%in%", target)
DF
name x1 x2 x3 x4
1 1 A 10 NA 20
2 1 A 11 NA 21
3 2 A 12 NA 22
4 2 A 13 NA 23
5 3 A 14 50 24
6 3 A
Thanks, the dataframe, is indeed clever at preserving its dimensions.
I'll try your solution with the real data
On Tue, Jun 22, 2010 at 12:23 M, Petr PIKAL wrote:
> Hi
>
> r-help-boun...@r-project.org napsal dne 22.06.2010 08:28:04:
>
> > The following dataframe will illustrate the problem
> >
The following dataframe will illustrate the problem
DF<-data.frame(name=rep(1:5,each=2),x1=rep("A",10),x2=seq(10,19,by=1),x3=rep(NA,10),x4=seq(20,29,by=1))
DF$x3[5]<-50
# we have a data frame. we are interested in the columns x2,x3,x4 which
contain sparse
# values and many NA.
DF
name x1
6 matches
Mail list logo