Dear R-user,
May I seek your suggestion. I have a data file 'stop' to be scanned in
R.
But I want to ignore one specific number '21' there. Putting
differently, I
want to get all numbers in the file except 21. Is there any command to
achieve it?
--------------------------------------------------------------
b<-scan("F:\\stop.txt")
--------------------------------------------------------------
Many thanks for your kind attention.
Regards,
Jamil.
-------------- next part --------------
15 15 16 15 17 16 16 15 17 15
16 17 19 17 19 15 16 16 19 18 19 17 17 19 16 17 16 20 15 16 16 15 18 19 17 18
16 18 16 17 21 21 17 15 15 20
16 20 17 21 19 15 15 15 18 20 16 17 16 15 16 15 16 16 18 16 15 21 20 15 16 17
18 18 20 17 18 18 21 16 15 16 20 17 19 17 18 19 17 21 21 16 15 19 21 15 20 20
16 16 20 18 21
21 15 15 19 15 16 15 17 15 21 20 16 15 16 16 18 17 16 18 16 16 16 21 16 15 20
16 19 17 14 17 15 16 15 17 16 15 15 20 15 16 15 15 16 15 20 19 15 15 17 17 15
18 16 15
14 21 19 20 15 17 15 15 17 19 15 15 16 18 17 16 16 16 16 18 21 15 16 16 21 19
17 15 16 15 18 16 20 17 16 16 21 15 17 20 21 16 16 17 21 16 16 20 19 17 15 16
18 16 16 15 16 18 19 16 15 21 20 19 20 20 20 16 18 16 15 20
16 16 18 19 16 18 21 16 21 19 19 17 18 15 18 16 19 17 20 20 16 18 16 19 20
21 15 16 18 19 16 17 16 15 17 16 15 21 16 15 18 18 15 21 19 16 19 15 15 17
18 17 16 15 16 18 18 19 17 16 21 16 19 16 15 16 20 17 17 21 21 20 16 17 19
16 15 19 18 17 15 15 15 19 20 18 21 16 15 15 20 20 17 19 15 19 16 15 15 19
16 16 19 15 15 19 18 21 15 15 18 21 16 16 17 17 16 15 18 16 15 20 17 20 15
16 15 15 20 15 16 17 16 17 16 21 17 18 17 15 20 18 16 17 16 17 15 15 17 20
17 18 15 16 20 16 15 15 18 16 18 16 18 15 16 18 15 17 18 18 16
15 19 16 19 21 15 20 17 18 15 16 19 17 16 18 18 15 19 15 15 17 15 19 19 16
20 16 16 15 19 15 16 15 16 15 15 17 20 15 20 16 20 15 17 16 15 16 16 16 17
16 16 21 21 15 15 17 16 16 19 20 16 16 16 16 15 16 16 20 16 16 20 18 19 15
21 16 15 15 21 20 20 19 17 15 17 16 18 17 15 16 16 14 19 21 15 17 15 16 19
20 19 18 15 15 16 18 15 17 20 21 16 19 16 18 16 16 20 21 20 20 18 21 18 15
21 20 15 21 15 18 16 16 18 17 20 15 15 17 18 20 15 21 19 19 16 20 16 19 15
15 15 18 21 17 20 18 18 19 16 20 20 18 16 18 15 15 15 15 18 19 15 17 15 16
15 15 18 16 19 15 19 15 18 15 19 21 21 18 21 16 17 17 16 16 17 16 18 20 16
20 20 21 16 16 20 15 16 21 19 19 17 19 16 19 21 18 16 15 17 18 21 15 15 16
16 15 17 20 15 18 17 20 17
On 4/3/2013 4:33 AM, Naser Jamil wrote:> Dear R-user, > May I seek your suggestion. I have a data file 'stop' to be scanned in R. > But I want to ignore one specific number '21' there. Putting differently, I > want to get all numbers in the file except 21. Is there any command to > achieve it? > > -------------------------------------------------------------- > > b<-scan("F:\\stop.txt") > > --------------------------------------------------------------Well, I don't know what is in stop.txt, but I will assume it is a string of numbers or strings separated by the end of line character and then a terminating EOL. Read it in as you have it and then: b <- b[-21] If you are reading in a dataframe, simply use what you have and then do: b <- b[-21, ] and you should have what you want, or perhaps you want b[21, ] <- NA # indicate row 21 as a missing value> Many thanks for your kind attention. > > Regards, > Jamil. > > > ______________________________________________ > 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.-- Robert W. Baer, Ph.D. Professor of Physiology Kirksille College of Osteopathic Medicine A. T. Still University of Health Sciences Kirksville, MO 63501 USA [[alternative HTML version deleted]]
You can certainly do it after scanning all the numbers in with
b <- scan("F:\\stop.txt", what=integer())
b <- b[b!=21]
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Naser Jamil
> Sent: Wednesday, April 03, 2013 4:33 AM
> To: R help
> Subject: [R] scanning data in R
>
> Dear R-user,
> May I seek your suggestion. I have a data file 'stop' to be
scanned in
> R.
> But I want to ignore one specific number '21' there. Putting
> differently, I
> want to get all numbers in the file except 21. Is there any command to
> achieve it?
>
> --------------------------------------------------------------
>
> b<-scan("F:\\stop.txt")
>
> --------------------------------------------------------------
>
> Many thanks for your kind attention.
>
> Regards,
> Jamil.
vec<- scan("stop.txt")
#Read 635 items
vec1<-vec[vec!=21]
?length(vec1)
#[1] 584
any(vec1==21)
#[1] FALSE
A.K.
----- Original Message -----
From: Naser Jamil <jamilnaser79 at gmail.com>
To: R help <r-help at r-project.org>
Cc:
Sent: Wednesday, April 3, 2013 5:33 AM
Subject: [R] scanning data in R
Dear R-user,
May I seek your suggestion.? I have a data file 'stop' to be scanned in
R.
But I want to ignore one specific number '21' there. Putting
differently, I
want to get all numbers in the file except 21. Is there any command to
achieve it?
--------------------------------------------------------------
b<-scan("F:\\stop.txt")
--------------------------------------------------------------
Many thanks for your kind attention.
Regards,
Jamil.
______________________________________________
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.
On Apr 3, 2013, at 2:33 AM, Naser Jamil wrote:> Dear R-user, > May I seek your suggestion. I have a data file 'stop' to be scanned in R. > But I want to ignore one specific number '21' there. Putting differently, I > want to get all numbers in the file except 21. Is there any command to > achieve it? > > -------------------------------------------------------------- > > b<-scan("F:\\stop.txt") >b<-scan("~/Downloads/stop.txt", na.strings="21") Read 635 items> b[1] 15 15 16 15 17 16 16 15 17 15 16 17 19 17 19 15 16 16 19 18 19 17 17 19 16 17 16 20 15 16 [31] 16 15 18 19 17 18 16 18 16 17 NA NA 17 15 15 20 16 20 17 NA 19 15 15 15 18 20 16 17 16 15 snipped remainder -- David Winsemius Alameda, CA, USA
I did not see a reply to your question. I don't know if you can do it within
scan but why not just read in the file and then drop the 21?
dat <- scan("stop.txt", sep = "\t")
dat1 <- dat[dat!= 21]
John Kane
Kingston ON Canada
> -----Original Message-----
> From: jamilnaser79 at gmail.com
> Sent: Wed, 3 Apr 2013 10:33:16 +0100
> To: r-help at r-project.org
> Subject: [R] scanning data in R
>
> Dear R-user,
> May I seek your suggestion. I have a data file 'stop' to be
scanned in
> R.
> But I want to ignore one specific number '21' there. Putting
differently,
> I
> want to get all numbers in the file except 21. Is there any command to
> achieve it?
>
> --------------------------------------------------------------
>
> b<-scan("F:\\stop.txt")
>
> --------------------------------------------------------------
>
> Many thanks for your kind attention.
>
> Regards,
> Jamil.
> ______________________________________________
> 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.
____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
http://www.inbox.com/smileys
Works with AIM?, MSN? Messenger, Yahoo!? Messenger, ICQ?, Google Talk? and most
webmails