[R] Hash Table - Select and Change Data iniside Matrix
arun
smartpink111 at yahoo.com
Fri May 25 20:19:12 CEST 2012
Hi Antony,
Try this,
da<-read.table(text="NAME AGE PLACE
ABC 20 INDIA
XYZ 30 FRANCE
PQR 40 USA
MNO 30 KENYA
DEF 25 AUSTRALIA", header=TRUE,stringsAsFactors=FALSE)
> da2<-function(x){
if(x==30)
TRUE
else
FALSE
}
da3<-sapply(da$AGE,da2)
TRUE_FALSE<-da3
da1<-data.frame(da,TRUE_FALSE)
da1
NAME AGE PLACE TRUE_FALSE
1 ABC 20 INDIA FALSE
2 XYZ 30 FRANCE TRUE
3 PQR 40 USA FALSE
4 MNO 30 KENYA TRUE
5 DEF 25 AUSTRALIA FALSE
A.K.
----- Original Message -----
From: Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
To: Rantony <antony.akkara at ge.com>; r-help at r-project.org
Cc:
Sent: Friday, May 25, 2012 10:25 AM
Subject: Re: [R] Hash Table - Select and Change Data iniside Matrix
Read help for the ifelse function. Type ?ifelse at the command line.
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
Rantony <antony.akkara at ge.com> wrote:
>Hi,
>
>Here i have been a matrix like this,
>
>*NAME AGE PALCE TRUE/FALSE*
>ABC 20 INDIA
>XYZ 30 FRANCE
>PQR 40 USA
>MNO 30 KENIYA
>DEF 25 AUSTRALIA
>
>Here,* TRUE/FALSE* Column containing empty values.
>
>So my requirement what is , need to change all the *TRUE/FALSE *column
>value
>into "*TRUE*" where *AGE = 30*.
>Note :- i *dont want* to use* any loop *and do. Main intension is avoid
>loop,bcz there is a bulk of data.
>
>Final Matrix should be like this
>*NAME AGE PALCE TRUE/FALSE*
>ABC 20 INDIA
>
>XYZ 30 FRANCE TRUE
>PQR 40 USA
>
>MNO 30 KENIYA TRUE
>DEF 25 AUSTRALIA
>
>
>Immediate Help Requied.
>
>Your,
>Antony.
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Hash-Table-Select-and-Change-Data-iniside-Matrix-tp4631312.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.
______________________________________________
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