[R] why "object 'x' not found"?
arun
smartpink111 at yahoo.com
Thu Feb 7 19:38:05 CET 2013
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 <winfried.moser at gmail.com>
To: r-help <r-help at r-project.org>
Cc:
Sent: Thursday, February 7, 2013 12:20 PM
Subject: [R] why "object 'x' not found"?
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 at 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.
More information about the R-help
mailing list