Dear R communtiy, I do not understand why this does not work...:> betaS$SBP[1] 0.03274 -0.04216 -0.08986 -0.45980 0.60320 -0.63070 -0.05682 0.20130> t<-c("betaS$SBP") > t[1] "betaS$SBP"> get(t)Error in get(t) : object 'betaS$SBP' not found [I am trying to use the variable "t" in a loop to call many different objects, but the pasting together did not work and this simple example does not neither...] Thank you and best regards, Georg. ******************* Georg Ehret JHU Baltimore [[alternative HTML version deleted]]
On 2/24/10, Georg Ehret <georgehret at gmail.com> wrote:> I do not understand why this does not work...: >Previously I ran into this and I am also curious why it doesn't work, but you can work around so:> x <- NULL > x$a <- 1:10 > x$b <- 11:20 > x$a [1] 1 2 3 4 5 6 7 8 9 10 $b [1] 11 12 13 14 15 16 17 18 19 20> get("x")[ "a"]$a [1] 1 2 3 4 5 6 7 8 9 10> get("x")[ "b"]$b [1] 11 12 13 14 15 16 17 18 19 20> t <- "a" > get("x")[ t]$a [1] 1 2 3 4 5 6 7 8 9 10 Liviu
On Feb 24, 2010, at 4:31 PM, Georg Ehret wrote:> Dear R communtiy, > I do not understand why this does not work...: > >> betaS$SBP > [1] 0.03274 -0.04216 -0.08986 -0.45980 0.60320 -0.63070 -0.05682 > 0.20130 >> t<-c("betaS$SBP") >> t > [1] "betaS$SBP" >> get(t) > Error in get(t) : object 'betaS$SBP' not foundA couple of different ways of passing multi-element objects to loops: > tt <- scan() 1: 0.03274 -0.04216 -0.08986 -0.45980 0.60320 -0.63070 -0.05682 0.20130 9: Read 8 items > tt [1] 0.03274 -0.04216 -0.08986 -0.45980 0.60320 -0.63070 -0.05682 0.20130 > for (xi in seq(tt)) print(xi) [1] 1 [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 > for (xi in seq(tt)) print(tt[xi]) [1] 0.03274 [1] -0.04216 [1] -0.08986 [1] -0.4598 [1] 0.6032 [1] -0.6307 [1] -0.05682 [1] 0.2013 > beta <-list() > beta$SBP <- tt > beta["SBP"] $SBP [1] 0.03274 -0.04216 -0.08986 -0.45980 0.60320 -0.63070 -0.05682 0.20130 > for (xi in seq_along(beta$SBP) ) print(xi) [1] 1 [1] 2 [1] 3 [1] 4 [1] 5 [1] 6 [1] 7 [1] 8 > for (xi in beta$SBP) print(xi) [1] 0.03274 [1] -0.04216 [1] -0.08986 [1] -0.4598 [1] 0.6032 [1] -0.6307 [1] -0.05682 [1] 0.2013 -- David.> > > [I am trying to use the variable "t" in a loop to call many different > objects, but the pasting together did not work and this simple > example does > not neither...] > > Thank you and best regards, Georg. > ******************* > Georg Ehret > JHU > Baltimore > > [[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 Heritage Laboratories West Hartford, CT
On 24/02/2010 4:31 PM, Georg Ehret wrote:> Dear R communtiy, > I do not understand why this does not work...: > > > betaS$SBP > [1] 0.03274 -0.04216 -0.08986 -0.45980 0.60320 -0.63070 -0.05682 0.20130 > > t<-c("betaS$SBP") > > t > [1] "betaS$SBP" > > get(t) > Error in get(t) : object 'betaS$SBP' not found >The problem is that betaS$SBP is an expression that extracts a component of the betaS object, it's not the name of an object. get() only gets single objects, it doesn't evaluate expressions. You need something like eval(parse(text=t)) to get what you want. Duncan Murdoch> > [I am trying to use the variable "t" in a loop to call many different > objects, but the pasting together did not work and this simple example does > not neither...] > > Thank you and best regards, Georg. > ******************* > Georg Ehret > JHU > Baltimore > > [[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. >
Possibly Parallel Threads
- Locate Patients who have multiple high blood pressure readings
- Howto overlay two plots and save them in one pdf file?
- [PATCH] Updated udp.c to use real client ip and subnetmask values if on local subnet
- two graphs
- [LLVMdev] Re: Re: New GCC4-based C/C++/ObjC front-end for LLVM