Quantcast

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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

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

miao
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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: How can I read the "text" or "character string" from a txt file?

jholtman
If the symbols are separated by spaces, try:

scan(yourFile, what = '')

Sent from my iPad

On May 2, 2012, at 2:36, jpm miao <[hidden email]> 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]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Loading...