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
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
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
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
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
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
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
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
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
...@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
10 matches
Mail list logo