Dirkheld
2008-May-07 07:20 UTC
[R] use list elements to subtract values from the dataframe
Hi, I have a dataframe wf existing of a header with different labels and beneath the values of those labels : wf: label1 label2 ... 0,45 0,21 0,10 0,45 .... .... I have a list fl <- c("label2","label3",..) Isn't possible to use the list elements in the list in order to subtract values from the dataframe? like : wf$fl[[1]] When I do in R I get :NULL fl[[1]] gives "label2" so no problem here... While wf$label1 works fine. -- View this message in context: http://www.nabble.com/use-list-elements-to-subtract-values-from-the-dataframe-tp17098923p17098923.html Sent from the R help mailing list archive at Nabble.com.
Ashish Ranpura
2008-May-07 08:50 UTC
[R] use list elements to subtract values from the dataframe
Dirkheld <dirk.bollen <at> soc.kuleuven.be> writes:> I have a dataframe wf existing of a header with different labels and beneath > the values of those labels : > wf: > label1 label2 ... > 0,45 0,21 > 0,10 0,45 > .... .... > > I have a list > fl <- c("label2","label3",..) > > Isn't possible to use the list elements in the list in order to subtract > values from the dataframe? like : > wf$fl[[1]] > When I do in R I get :NULL > fl[[1]] gives "label2" so no problem here... > > While wf$label1 works fine. >Dirk, possibly not the most elegant solution, but I would use: f1.indices = match(f1, names(wf)) wf[f1.indices[1]] Good luck, -Ash. --- ----- Ashish Ranpura Institute of Cognitive Neuroscience University College London 17 Queen Square London WC1N 3AR tel: +44 (20) 7679 1126 web: http://www.icn.ucl.ac.uk
jim holtman
2008-May-07 09:40 UTC
[R] use list elements to subtract values from the dataframe
What you want is: wf[[fl[1]]] 'fl' is a vector, so you should only be using a single '[' for indexing. On Wed, May 7, 2008 at 3:20 AM, Dirkheld <dirk.bollen at soc.kuleuven.be> wrote:> > Hi, > > I have a dataframe wf existing of a header with different labels and beneath > the values of those labels : > wf: > label1 label2 ... > 0,45 0,21 > 0,10 0,45 > .... .... > > I have a list > fl <- c("label2","label3",..) > > Isn't possible to use the list elements in the list in order to subtract > values from the dataframe? like : > wf$fl[[1]] > When I do in R I get :NULL > fl[[1]] gives "label2" so no problem here... > > While wf$label1 works fine. > > > > -- > View this message in context: http://www.nabble.com/use-list-elements-to-subtract-values-from-the-dataframe-tp17098923p17098923.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Julian Burgos
2008-May-07 17:37 UTC
[R] use list elements to subtract values from the dataframe
Try get(paste("wf$",fl[[1]],sep="")) See ?get Julian Dirkheld wrote:> Hi, > > I have a dataframe wf existing of a header with different labels and beneath > the values of those labels : > wf: > label1 label2 ... > 0,45 0,21 > 0,10 0,45 > .... .... > > I have a list > fl <- c("label2","label3",..) > > Isn't possible to use the list elements in the list in order to subtract > values from the dataframe? like : > wf$fl[[1]] > When I do in R I get :NULL > fl[[1]] gives "label2" so no problem here... > > While wf$label1 works fine. > > >