[R] Odp: Data manipulation in R

Petr PIKAL petr.pikal at precheza.cz
Fri Sep 24 12:20:10 CEST 2010


Hi

r-help-bounces at r-project.org napsal dne 24.09.2010 05:41:30:

> If this has already been answered, my apologies in advance I am 
relatively
> new to this aspect of [R]. it is a bit of a basic question.
> 
> 
> 
> I have 4 columns of data (site, Date, measurement type, value) in a tab
> delimited text file.  Site is a site where measurements were collected,
> Date is a date in DD/MM/YYYY format, measurement is a code for the type 
of
> measurement made, and value just the value observed. 
> 
> 
> 
> So each site has multiple dates on which it was sampled and each date 
has
> multiple measurement types (fortunately only one value per measurement 
type
> per day).
> 
> 
> 
> I want to know how I can separate this into multiple columns by 
measurement
> type averaged over the range of dates available.  The output would have 
a
> single averaged measurement value per site.

Try to look at reshape function or reshape package.

> 
> 
> 
> Site, Measurement 1, measurement2, measurement3, etc. 
> 
> 
> 
> I have been reading it in as a matrix as.matrix(read.table("myfile.txt",
> headers=TRUE)), but I don't quite know what to do with it afterward.

Do not do that!!!!. read.table reads your data as data frame (correct) but 
you transform them to matrix and it wil result in ***character*** matrix 
as matrices can have values of only one type. See Intro manual which shall 
come with your installation of R (chapters 5 and 6). Well and if you are 
in reading you'd better go through thole document. With 100 pages it is 
not so big and you want to read only basics it is in first 30 pages.

Regards
Petr


> 
> 
> 
> Thanks
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> 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