Hi Antony,
I am sending this message again as it was not yet posted by the rhelp.
?
One more solution:
dat2<-read.table(text="
?ABC PQR XYZ
?42? 29? 22
?65? 22? 78? ???
?10? 20? 30
?40? 50? 60
?70? 80? 90
?61? 15? 24?
?",sep="",header=T)
exprv <- expression(c( ABC>10 & XYZ <30 & PQR <90,ABC >9
& XYZ <25 & PQR <60,ABC >60 & XYZ <79 & PQR
<100))
dat3<-list(ABC=dat2[,1],PQR=dat2[,2],XYZ=dat2[,3])
res1<-sapply(exprv,function(x) with(dat3,eval(x)))
res2<-data.frame("ABC_CHECK"=res1[1:6,],"XYZ_CHECK"=res1[7:12,],"PQR_CHECK"=res1[13:18,])
resultA<-data.frame(dat2,res2)
resultA
? ABC PQR XYZ ABC_CHECK XYZ_CHECK PQR_CHECK
1? 42? 29? 22????? TRUE????? TRUE???? FALSE
2? 65? 22? 78???? FALSE???? FALSE????? TRUE
3? 10? 20? 30???? FALSE???? FALSE???? FALSE
4? 40? 50? 60???? FALSE???? FALSE???? FALSE
5? 70? 80? 90???? FALSE???? FALSE???? FALSE
6? 61? 15? 24????? TRUE????? TRUE????? TRUE
# which is the same as the one below.
A.K.
----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: "Akkara, Antony (GE Energy, Non-GE)" <Antony.Akkara at
ge.com>
Cc: R help <r-help at r-project.org>
Sent: Friday, June 1, 2012 7:21 PM
Subject: Re: [R] Separate Array Variable Content
Hi Antony,
I guess I understood the format you needed.? I assume that there are only few
conditions in the second matrix.
Based on the information given, I would do:
dat1<-read.table(text="
?ABC PQR XYZ
?42? 29? 22
?65? 22? 78? ???
?10? 20? 30
?40? 50? 60
?70? 80? 90
?61? 15? 24?
?",sep="",header=T)
#I added some more datapoints
dat1[dat1$ABC > 10 & dat1$XYZ < 30 & dat1$PQR <
90,"ABC_CHECK"]<-TRUE
dat1[dat1$ABC > 9 & dat1$XYZ < 25 & dat1$PQR <
60,"XYZ_CHECK"]<-TRUE
dat1[dat1$ABC > 60 & dat1$XYZ < 79 & dat1$PQR <
100,"PQR_CHECK"]<-TRUE
dat1[is.na(dat1)]<-"FALSE"
?> dat1
? ABC PQR XYZ ABC_CHECK XYZ_CHECK PQR_CHECK
1? 42? 29? 22????? TRUE????? TRUE???? FALSE
2? 65? 22? 78???? FALSE???? FALSE????? TRUE
3? 10? 20? 30???? FALSE???? FALSE???? FALSE
4? 40? 50? 60???? FALSE???? FALSE???? FALSE
5? 70? 80? 90???? FALSE???? FALSE???? FALSE
6? 61? 15? 24????? TRUE????? TRUE????? TRUE
#if your data is in matrix format, convert it to dataframe.
dat1<-as.matrix(dat1)
dat1<-data.frame(dat1)
I hope this helps.
A.K.
----- Original Message -----
From: "Akkara, Antony (GE Energy, Non-GE)" <Antony.Akkara at
ge.com>
To: arun <smartpink111 at yahoo.com>
Cc:
Sent: Friday, June 1, 2012 2:15 AM
Subject: RE: [R] Separate Array Variable Content
Hi Arun,
What you showed, same like I am also expecting.
There is two matrix,
??? 1) 1st - matrix contain values like this,
??? ??? ABC? ? ?? XYZ? ?? PQR? ? ?? ABC_CHECK? ? ?? XYZ_CHECK? ? ?? PQR_CHECK
??? ??? ----??? ----? ?? ----? ? ? ? ----------------? ? ? --------------? ? ??
-----------------??? ??? ???
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? 10? ??? 20? ? ? ?? 30
??? ???? 40??? 50? ? ? ?? 60
??? ???? 70??? 80? ? ? ?? 90
??? 2)2nd matrix have some conditions, need to check with? 1st matrix columns.
Like this,
??? ???
??? ??? CHECK FOR??? ??? ??? CONDITION
??? ??? --------------??? ??? ??? -----------------
??? ??? ABC_CHECK??? ??? ??? ABC > 10 & XYZ < 30 & PQR <90
??? ??? XYZ_CHECK??? ??? ??? ABC > 9 & XYZ < 25 & PQR <60
??? ??? PQR_CHECK??? ??? ??? ABC > 60 & XYZ < 79 & PQR <100
So,
??? Finally the result should get like this,
??? ??? ABC? ? ?? XYZ? ?? PQR? ? ?? ABC_CHECK? ? ?? XYZ_CHECK? ? ?? PQR_CHECK
??? ??? ----??? ----? ?? ----? ? ? ? ----------------? ? ? --------------? ? ??
-----------------??? ??? ???
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? 10? ??? 20? ? ? ?? 30??? FALSE??? ??? TRUE???
??? FALSE
??? ???? 40??? 50? ? ? ?? 60??? FALSE??? ??? FALSE??? ??? FALSE
??? ???? 70??? 80? ? ? ?? 90??? FALSE??? ??? FALSE??? ??? TRUE
And can please tell me which is the best way to do this ?, Can we do this
with-out loop ?
- Thanks
Antony.
-----Original Message-----
From: arun [mailto:smartpink111 at yahoo.com]
Sent: Wednesday, May 30, 2012 10:43 PM
To: Akkara, Antony (GE Energy, Non-GE)
Cc: R help
Subject: Re: [R] Separate Array Variable Content
HI Antony,
I am not sure how you want the result.
Is it something like this?? Also, do you have lots of conditions in the array?
> Mydat2
? ABC PQR XYZ ELIGIBLE_ABC ELIGIBLE_PQR ELIGIBLE_ABC_XYZ
1? 10? 20?
30?????????????????????????????????????????????????????????????????????? TRUE
2? 40? 50? 60
3? 70? 80? 90???????? TRUE???????????? TRUE????????????????
A.K.
----- Original Message -----
From: Rantony <antony.akkara at ge.com>
To: r-help at r-project.org
Cc:
Sent: Wednesday, May 30, 2012 2:44 AM
Subject: [R] Separate Array Variable Content
Hi,
I am new in R,
i have a matrix like this
MyMatrix <-
*ABC?? PQR? ? XYZ*
10? ? ?? 20? ? ? ? 30
40? ? ?? 50? ? ? ? 60
70? ? ?? 80? ? ? ? 90
And, i have an array containing some conditions like this, MyArray <-?
c("*ABC*>50","*PQR*<50","*ABC*<30 &*
XYZ*<40")
"ABC>50"
"PQR<50"
"ABC<30 & XYZ<40"
My purpose what is, i need to check this conditions in *MyArray* with
*MyMatrix* value for particular column
How it is possible ?
- Thanks
Antony.
--
View this message in context:
http://r.789695.n4.nabble.com/Separate-Array-Variable-Content-tp4631800.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
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.