[R] Newbie in R: Reading .txt files and storing the 'numbers' in a vector

Patrick Schorderet patrick.schorderet at epfl.ch
Wed Jul 29 10:29:24 CEST 2009


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




More information about the R-help mailing list