[R] problem with grep under loop

arun smartpink111 at yahoo.com
Sat Sep 14 04:05:32 CEST 2013


Hi,
Try:
for(i in 1:10) {print(grep("a",letters))}
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1
[1] 1

x<- vector()
 for(i in 1:10) {x[i]<-grep("a",letters) }
 x
# [1] 1 1 1 1 1 1 1 1 1 1
A.K.





----- Original Message -----
From: capricy gao <capricyg at yahoo.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Friday, September 13, 2013 9:29 PM
Subject: [R] problem with grep under loop



I am just testing the possibility of using grep under for loop:

>for(i in 1:10){grep("a",letters)}


nothing came out;

when I ran: 


>grep("a",letters), 


I got "1"

so in my for loop, I expected to see ten "1"s, but I did not.

Could anybody help me to figure out why? Thanks a lot for your help.

Capricy
    [[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