Re: [R] why object 'x' not found?

2013-02-07 Thread jim holtman
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.mo...@gmail.com wrote: Dear

Re: [R] why object 'x' not found?

2013-02-07 Thread Duncan Murdoch
On 07/02/2013 1:20 PM, Winfried Moser 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

Re: [R] why object 'x' not found?

2013-02-07 Thread arun
Hi, You could get the result: dat1 - read.table(text = v1 v2 v3  1   0   0  0   1   0  0   0   1 ,sep=,header=TRUE) dat1$v4-apply(mapply(`==`,dat1,1),2,which)  dat1  # v1 v2 v3 v4 #1  1  0  0  1 #2  0  1  0  2 #3  0  0  1  3 A.K. - Original Message - From: Winfried Moser

Re: [R] why object 'x' not found?

2013-02-07 Thread Winfried Moser
thank's, that worked! 2013/2/7 jim holtman jholt...@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

Re: [R] why object 'x' not found?

2013-02-07 Thread Winfried Moser
thanks, that worked! 2013/2/7 arun smartpink...@yahoo.com Hi, You could get the result: dat1 - read.table(text = v1 v2 v3 1 0 0 0 1 0 0 0 1 ,sep=,header=TRUE) dat1$v4-apply(mapply(`==`,dat1,1),2,which) dat1 # v1 v2 v3 v4 #1 1 0 0 1 #2 0 1 0 2 #3 0 0 1

Re: [R] why object 'x' not found?

2013-02-07 Thread David Winsemius
On Feb 7, 2013, at 10:20 AM, Winfried Moser 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

Re: [R] why object 'x' not found?

2013-02-07 Thread Winfried Moser
thanks! I didn't know, that x$y isn't a variable, but an expression! with the suggested notation d[[x]] i get a matrix and have to extract the diagonale. 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(d[[x]]==**1,x,d$nr)) [,1] [,2] [,3] [1,]1

Re: [R] why object 'x' not found?

2013-02-07 Thread Andrew Robinson
Hi David, The following is an interesting observation ... On Friday, February 8, 2013, David Winsemius wrote: On Feb 7, 2013, at 10:20 AM, Winfried Moser wrote: Notice that the '[[' function is superior in every way to the '$' function. I'm curious to know whether you can point to

Re: [R] why object 'x' not found?

2013-02-07 Thread William Dunlap
Winsemius Cc: r-help Subject: Re: [R] why object 'x' not found? Hi David, The following is an interesting observation ... On Friday, February 8, 2013, David Winsemius wrote: On Feb 7, 2013, at 10:20 AM, Winfried Moser wrote: Notice that the '[[' function is superior in every way

Re: [R] why object 'x' not found?

2013-02-07 Thread Andrew Robinson
...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Andrew Robinson Sent: Thursday, February 07, 2013 12:52 PM To: David Winsemius Cc: r-help Subject: Re: [R] why object 'x' not found? Hi David, The following is an interesting observation ... On Friday