jpm miao
2012-May-02 06:36 UTC
[R] How can I read the "text" or "character string" from a txt file?
Hello, I have a large number of time series, which needs to be transformed by log or difference. Some of them are just processed by "level" (LV) without any transformation. For that purpose, I produce a text file (.csv or .xls) as follows: DLN DLNDLN LV LV LV....... How can I read the preceding strings so that I can easily access them, i.e., S[1]=DLN, S[2]=DLN, S[3]=DLN, S[4]=LV,S[5]=LV,S[6]=LV? I tried read.csv and read.table, but they don't work well. If I can access the string, then I will be able to write an "if" statement so that If the string is DLN, then take log and then difference. If the string is LV, then just keep it as it is. Thanks, miao [[alternative HTML version deleted]]
Jim Holtman
2012-May-02 10:19 UTC
[R] How can I read the "text" or "character string" from a txt file?
If the symbols are separated by spaces, try: scan(yourFile, what = '') Sent from my iPad On May 2, 2012, at 2:36, jpm miao <miaojpm at gmail.com> wrote:> Hello, > > I have a large number of time series, which needs to be transformed by > log or difference. Some of them are just processed by "level" (LV) without > any transformation. For that purpose, I produce a text file (.csv or .xls) > as follows: > > DLN DLNDLN LV LV LV....... > > How can I read the preceding strings so that I can easily access them, > i.e., S[1]=DLN, S[2]=DLN, S[3]=DLN, S[4]=LV,S[5]=LV,S[6]=LV? I tried > read.csv and read.table, but they don't work well. If I can access the > string, then I will be able to write an "if" statement so that > > If the string is DLN, then take log and then difference. > If the string is LV, then just keep it as it is. > > Thanks, > > miao > > [[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.
Reasonably Related Threads
- How can I read time series data to create zoo objects if I have two title lines?
- Why can't R understand if(num!=NA)?
- Definition of "lag" is opposite in ts and xts objects!
- How can I tabulate time series data (in RStudio or any other R editor)?
- How can we access an element in a structure