[R] Using data frame col names and variables
David Winsemius
dwinsemius at comcast.net
Fri Jul 30 23:01:34 CEST 2010
On Jul 30, 2010, at 2:12 PM, Cadmium 2 wrote:
> Hi to you all!
>
> I'm new to R and to this mailing list, so do please excuse me if my
> question
> sounds stupid.
>
> Currently I'm working with a data frame called "results".
>
> In each column of "results" I have a set of results for different
> experiments (all results are numerical) realized in different
> dates, so
> that each row corresponds to a day.
>
> To make it clear when displaying the results, I gave names to the
> columns
> with the names of the experiments realized. I also gave names to the
> rows
> based on the day the experiments where realized.
>
> My problem now is that I'm trying to separate this experiments based
> on a
> criteria that is not important for the moment. What I want to be
> able to do
> is, given an experiment name, obtain the time series of the results
> of that
> experiment.
>
> I know I can do this by typing
>
> results$nameoftheexperiment
>
> But what if I have a variable "name" which contains the experiment's
> name?
>
> Doing the following
>
> results$name
>
> doesn't work, as expected, since there is no column with name name.
Try:
results[ , name]
And read the the help page for ?Extract. The $ formalism does not
evaluate its argument whereas the [ function does.
--
David.
>
> Any help would be appreciated.
>
> Thank you very much!
>
> [[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.
David Winsemius, MD
West Hartford, CT
More information about the R-help
mailing list