Hi dre968.
Take a look at this:
> strings <-
c('ABC','DFC','AWS','','ABC','POK','MKL')
> strings
[1] "ABC" "DFC" "AWS" ""
"ABC" "POK" "MKL"
> strings=='ABC'
[1] TRUE FALSE FALSE FALSE TRUE FALSE FALSE
> sapply(strings, function(x) x=='ABC')
ABC DFC AWS ABC POK MKL
TRUE FALSE FALSE FALSE TRUE FALSE FALSE
You can easily use *apply() through your data to get what you want.
HTH,
Jorge
On Wed, Apr 22, 2009 at 3:39 PM, dre968 <alyalko@gmail.com> wrote:
>
> I read in a CSV file with Data <-
> read.csv(file="FileName.csv",head=TRUE,sep=",")
>
> the file containts strings in the 2nd and 3rd columns and each has about
> 1000 rows. I need to either loop through the strings there looking for
> strings that would trigger other logic or remove those rows and put them in
> another array and loop through them in the new array. I can't seem to
get
> the if statement to work on the Data strings. it doesn't recognize the
> string. Oh the strings in the CSV file all have "" around them
so
> Data[1,2]
> is "ABC" but...
>
> > if(Data[1,2]=="ABC") tester<-"True" else
tester<-"False"
> > tester
> [1] "False"
>
>
> What am I doing wrong?
>
> --
> View this message in context:
>
http://www.nabble.com/How-do-I-loop-through-strings--tp23175824p23175824.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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.
>
[[alternative HTML version deleted]]