thank's, that worked!

2013/2/7 jim holtman <jholtman@gmail.com>

> try this:
>
> > x <- read.table(text = "v1 v2 v3
> + 1   0   0
> + 0   1   0
> + 0   0   1", header = TRUE)
> >
> > x$v4 <- apply(x, 1, function(a) which(a == 1))
> > x
>   v1 v2 v3 v4
> 1  1  0  0  1
> 2  0  1  0  2
> 3  0  0  1  3
> >
> >
> >
>
>
> On Thu, Feb 7, 2013 at 1:20 PM, Winfried Moser <winfried.moser@gmail.com>
> wrote:
> > Dear Listers,
> >
> > I try to change the structure of my data. i have an indicator-matrix and
> > want to end up with a factor.
> >
> > i have
> >
> > v1 v2 v3
> > 1   0   0
> > 0   1   0
> > 0   0   1
> >
> > and want
> >
> > v1 v2 v3  v4
> > 1   0   0   1
> > 0   1   0   2
> > 0   0   1   3
> >
> > amongst other things i tried the following
> >
> > d <- data.frame(d1=c(1,0,0), d2=c(0,1,0), d3=c(0,0,1))
> > d$nr <- NA
> > sapply(1:3, function(x) ifelse(get(paste0("d$d",x))==1,x,d$nr))
> >
> > >From R i get the message "Object 'd$d1' not found".
> > But why, it's there?
> >
> > Thanks a lot.
> > Winfried
> >
> >         [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>
>
> --
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>

	[[alternative HTML version deleted]]

