[R] Newbie in R: Reading .txt files and storing the 'numbers' in avector
ONKELINX, Thierry
Thierry.ONKELINX at inbo.be
Wed Jul 29 10:34:52 CEST 2009
Have a look at ?read.table
HTH,
Thierry
------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
methodology and quality assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium
tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
Namens Patrick Schorderet
Verzonden: woensdag 29 juli 2009 10:29
Aan: r-help at r-project.org
Onderwerp: [R] Newbie in R: Reading .txt files and storing the 'numbers'
in avector
Hello everybody,
I'm a newbie in R and just went through an introduction class recently.
Here's my problem.
I have 2 text files (.txt) with plain numbers ('doubles' for those who
know c++) ordered into 2 columns as below:
coordinate1 value1
coordinate2 value2
coordinate3 value3
... ...
coordinateN valueN
I would like to write a small programme in which i would:
1. take all values of file 1 and store them in a vector 2. substract to
those all values of file 2 (one by one) and store the result in a new
vector 3. Create a sliding window of chosen size and calculate the
mathematical average and store these averages in a new vector 4. Plot
the different graphes with a bar plot
So I wrote a c++ script that does the first parts and writes the
averages in a output.txt file (which I have up and running).
Unfortunately, I seem to fail in reading these as numbers and putting
them into a vector (in the R environment). I can read the file , but
this is what I get:
> z=scan(file = "/Users/NCCRGENETICS/Desktop/testRnumbers.txt", what =
"double") Read 19 items > z
[1] "{\\rtf1\\ansi\\ansicpg1252\\cocoartf949\\cocoasubrtf430"
[2] "{\\fonttbl\\f0\\fswiss\\fcharset0"
[3] "Helvetica;}"
[4] "{\\colortbl;\\red255\\green255\\blue255;}"
[5] "\\paperw11900\\paperh16840\\margl1440\\margr1440\\vieww9000\
\viewh8400\\viewkind0"
[6] "\\pard\\tx566\\tx1133\\tx1700\\tx2267\\tx2834\\tx3401\\tx3968\
\tx4535\\tx5102\\tx5669\\tx6236\\tx6803\\ql\\qnatural\\pardirnatural"
[7] "\\f0\\fs24"
[8] "\\cf0"
[9] "13\\" // This is where my file
"should" start
reading the numbers I see in the window when I open it with textedit
[10] "27\\"
[11] "39\\"
[12] "48\\"
[13] "34\\"
[14] "17\\"
[15] "23\\"
[16] "45\\"
[17] "23\\"
[18] "4\\"
[19] "}"
>
Thanks so much to any of you who could provoid a little help... I'm
getting nuts.
Patrick
______________________________________________
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.
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in this message
and any annex are purely those of the writer and may not be regarded as stating
an official position of INBO, as long as the message is not confirmed by a duly
signed document.
More information about the R-help
mailing list