[R] Reading Strings in R

Michael Bedward michael.bedward at gmail.com
Mon Oct 4 13:36:52 CEST 2010


Try thist...

your.strings <- scan("yourfilename.dat", what="")

Michael

On 4 October 2010 22:04, Lorenzo Isella <lorenzo.isella at gmail.com> wrote:
> Dear All,
> I know this must be a one-liner, but I am experiencing problems.
> I need to read lists of long integers stored on a text files, i.e. which
> reads like
>
> "7359700484475972"
> "7359700484475972"
> "0"
> "7359700484475972"
> "0"
> "0"
> "0"
> "97189954101318722"
> "0"
> "0"
> "7811896690636354"
> "7359700490636354"
> "0"
> "0"
> "0"
> "7811896684475972"
> "7811896684475972"
> "7811896690636354"
> "8447597298304052"
> "7359700484475972"
> "0"
> "7359700498304052"
> "7359700498304052"
> "7359700498304052"
> "0"
> "7359700498304052"
> "7359700484475972"
> "7359700484475972"
>
> Now, for me every integer is just a symbol, i.e. the ID of some object and I
> simply need to find out how many times and where it occurs in this file.
> Bottom line: I would like to read this file directly as a string to ensure I
> will not have any trouble of integer overflow or rounding error.
> I tried readLines, but I cannot get rid of \n.
> Any help is appreciated.
> Cheers
>
> Lorenzo
>
> ______________________________________________
> 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