This reads in your posted data:

> x <- read.table(textConnection("Samplerate = 2 samps/sec
+       Nr   Cnt1X   Cnt1Y   Cnt2X   Cnt2Y  sec100  hour
+  1    53      84      43      2       22      12
+  2    90      155     74      0       72      12
+  3    90      155     74      0       121     12"), skip=1, header=TRUE)
> closeAllConnections()
>
> x
  Nr Cnt1X Cnt1Y Cnt2X Cnt2Y sec100 hour
1  1    53    84    43     2     22   12
2  2    90   155    74     0     72   12
3  3    90   155    74     0    121   12


On Wed, Dec 23, 2009 at 8:31 PM, arthurbeer01 <arthur_b...@hotmail.com>wrote:

>
> Hi, this is my first post so please be gentle.
> I quite new to R and using it for my biology degree.
>
> My problem is. Im trying to import data from a .csv file using the
> read.table command. The .csv file header starts on row 2 but is contained
> in
> column 1, i have 600 data files and for future ease would rather not edit
> each file seperatly. The data starts on row three and I only need the first
> 381 data points.
>
> The R error message using the code iv got so far is
>
> Error in read.table(file("s1-2c83.csv"), header = FALSE, sep = ",", quote =
> "",  :
>  more columns than column names
>
> The code I have so far is
>
> framename<-read.table(file ("s1-2c83.csv"),
> header = FALSE, # FLASE indicates headers are not included in input file
> sep = ",",    # must have "," otherwise errors in table
> quote = "",
> dec = ".",
> row.names = 1, # must = 1 or extra column of row numbering is entered
> col.names = ("Nr2sec,Cnt1X,Cnt1Y,Cnt2X,Cnt2Y,sec100,hour"),
> as.is = FALSE,
> na.strings = "NA",
> colClasses = NULL,
> nrows = 381, # rows to stop data.table recording (not input file row
> number!)
> skip = 2,    # number of rows to skp before reading data from input file
> strip.white = FALSE,
> comment.char = "")
>
> write.csv(framename, file = "s1-2c83-ok.csv")
>
> If I delete the line col.names, Iv manged to get the data read and saved to
> a new .csv file but cannot work out how to get the column headers renamed.
> The read.table (framename) displays the headers as v1,v2,v3 etc, this is
> what i cant change. Also it has the first column without a header (i think
> its the row number) which I dont want in the output file
>
> The read data file example s1-2c83.csv
>
> 1:Samplerate = 2 samps/sec
> 2:      Nr   Cnt1X   Cnt1Y   Cnt2X   Cnt2Y  sec100  hour
> 3: 1    53      84      43      2       22      12
> 4: 2    90      155     74      0       72      12
> 5: 3    90      155     74      0       121     12
>
> Any help will be greatly appreciated after the 5hrs Iv spent already on
> this
> problem.
>
> Many thanks in advance
>
>  Adam
>
>
>
> --
> View this message in context:
> http://n4.nabble.com/Column-naming-issues-using-read-table-tp978241p978241.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help@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<http://www.r-project.org/posting-guide.html>
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to