[R] How can I read the "text" or "character string" from a txt file?

Jim Holtman jholtman at gmail.com
Wed May 2 12:19:15 CEST 2012


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.



More information about the R-help mailing list