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. 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. Thanks [[alternative HTML version deleted]]
Hi: Please provide a minimal reproducible example that resembles your real data so that people can try it out and provide potential solutions for you. Show what you tried that failed, and what you expect. A number of people on this list are very adept in data summarization, but most of them are loath to provide abstract solutions unless the problem is crystal clear. On Thu, Sep 23, 2010 at 8:41 PM, Thomas Parr <thomasbparr@gmail.com> wrote:> 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. > > > This suggests you may need to reshape your data first.> > Site, Measurement 1, measurement2, measurement3, etc. > > > Matrices are OK, data frames are usually better.> 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. > > There are several functions/packages that are more than capable of solvingyour problem, but it would be a lot easier and more productive if you provide a concrete example. HTH, Dennis> > > Thanks > > > > > > > > > > > > > [[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. >[[alternative HTML version deleted]]
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 amrelatively> 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 typeof> measurement made, and value just the value observed. > > > > So each site has multiple dates on which it was sampled and each datehas> multiple measurement types (fortunately only one value per measurementtype> per day). > > > > I want to know how I can separate this into multiple columns bymeasurement> type averaged over the range of dates available. The output would havea> 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 guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.