[R] how to read a file containing a series filename

Jie Tang totangjie at gmail.com
Wed Mar 7 15:48:53 CET 2012


here is my file.txt that generated by other command "ls "

2012/3/7 Jie Tang <totangjie at gmail.com>

> there is something wrong :
>
> scan(file, what, nmax, sep, dec, quote, skip, nlines, na.strings,  :
>   scan() needs 'a real', but not 'H20100903.TXT'
>
> 2012/3/7 jim holtman <jholtman at gmail.com>
>
>> This works fine for me; look at your options on 'scan':
>>
>>
>> > x <- scan(text = "H20100902.TXT
>> + H20100903.TXT
>> + H20100904.TXT
>> + H20100905.TXT
>> + H20100906.TXT
>> + H20100907.TXT
>> + H20100908.TXT", what = '')
>> Read 7 items
>> > cat(x, file = 'file.txt', sep = '\n')  # create the 'file.txt'
>> >
>> > files <- scan('file.txt', what = '')  # read names from the file
>> Read 7 items
>> > files  # display the names
>> [1] "H20100902.TXT" "H20100903.TXT" "H20100904.TXT" "H20100905.TXT"
>> "H20100906.TXT"
>> [6] "H20100907.TXT" "H20100908.TXT"
>> >
>>
>>
>> On Wed, Mar 7, 2012 at 8:49 AM, Jie Tang <totangjie at gmail.com> wrote:
>> > hi everyone .
>> > I have a group of files that needs to be read in .
>> > And I put their filename into one file with the name "file.txt"
>> >
>> > And in the file.txt,the filename are shown as below :
>> > H20100902.TXT
>> > H20100903.TXT
>> > H20100904.TXT
>> > H20100905.TXT
>> > H20100906.TXT
>> > H20100907.TXT
>> > H20100908.TXT
>> >
>> > Now I want to read these file from the file.txt by such  codes:
>> >
>> >
>> > filename <-("file.txt")
>> >
>> > pp <- scan(filename,what=list(""),sep=" ")
>> >
>> > but R shows  that :
>> >> pp
>> > [[1]]
>> >
>> > that is pp is just one dimension data?
>> >
>> > but when I type
>> >>pp[1]
>> > the filenames are shown.
>> >
>> > How could I read these filenames into one array
>> > and so that .I can read the data by such a command ?
>> >
>> > ddata<-scan(pp[2],what=datalist,na.strings = 999)
>> >
>> > thank you .
>> > --
>> > TANG Jie
>> > Email: totangjie at gmail.com
>> > Tel: 0086-2154896104
>> > Shanghai Typhoon Institute,China
>> >
>> >        [[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.
>>
>>
>>
>> --
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>>
>
>
>
> --
> TANG Jie
> Email: totangjie at gmail.com
> Tel: 0086-2154896104
> Shanghai Typhoon Institute,China
>



-- 
TANG Jie
Email: totangjie at gmail.com
Tel: 0086-2154896104
Shanghai Typhoon Institute,China
-------------- next part --------------
H20080728.TXT
H20090808.TXT
H20090809.TXT
H20100830.TXT
H20100831.TXT
H20100901.TXT
H20100902.TXT
H20100903.TXT
H20100904.TXT
H20100905.TXT
H20100906.TXT
H20100907.TXT
H20100908.TXT
H20100909.TXT
H20100910.TXT
H20100911.TXT
H20100912.TXT
H20100913.TXT
H20100914.TXT
H20100915.TXT
H20100916.TXT
H20100917.TXT
H20100918.TXT
H20100919.TXT
H20100920.TXT
H20100921.TXT
H20100922.TXT
H20100923.TXT
H20100924.TXT
H20100925.TXT
H20100926.TXT
H20100927.TXT
H20100928.TXT
H20100929.TXT
H20100930.TXT
H20101001.TXT
H20101002.TXT
H20101003.TXT
H20101004.TXT
H20101005.TXT
H20101006.TXT
H20101007.TXT
H20101008.TXT
H20101009.TXT
H20101010.TXT
H20101011.TXT
H20101012.TXT
H20101013.TXT
H20101014.TXT
H20101015.TXT
H20101016.TXT
H20101017.TXT
H20101018.TXT
H20101019.TXT
H20101020.TXT
H20101021.TXT
H20101022.TXT
H20101023.TXT
H20101024.TXT


More information about the R-help mailing list