[R] referencing a data frame with a pointer, link, alias, etc

David Winsemius dwinsemius at comcast.net
Fri May 30 01:02:35 CEST 2014


On May 29, 2014, at 2:54 PM, Dan Sawyer wrote:

> Thanks for the follow up.
> 
> I will look into changing the column reverences.

Please look into reading the Posting Guide. You are asked NOT to respond privately but rather to the list.

As teh footer of every message says: PLEASE do read the posting guide http://www.R-project.org/posting-guide.html


> 
> The question is still open: Does R support indirect reference to data frames. Further experimentation is not finding anything.


You need to define your terms. What would be evidence that R did or did not "support indirect reference to data.frames"?

If my indirection you mean interpretation of a vlaue before being used as an index then I showed you how to do that:

indirf <- function(dfrm, col) {dfrm[[col]]}

mydf <- data.frame(a=1:10, b=10:1)

mycol <- "b"

indirf(mydf, mycol) 
#[1] 10  9  8  7  6  5  4  3  2  1 

-- 
David

> Dan
> 
> On 05/29/2014 02:02 PM, David Winsemius wrote:
>> On May 29, 2014, at 1:13 PM, dansawyer wrote:
>> 
>>> Good afternoon.
>>> 
>>> The question is: does R support pointer like structures? The specific
>>> problem is:
>>> 
>>> a function supporting operations on a set of data frames with similar
>>> structures.
>>> 
>>> I have a set of data frames with similar structures. I wish to perform
>>> similar operations on those data frames. I have successfully created and
>>> tested the operations and am ready to write a local function to perform
>>> them. To clarify the question below is a pigeon example for the question:
>>> 
>>> df1 <- (col1, col2, ...)
>>> df2 <- (col1, col2, ...)
>> Not valid R code.
>> 
>>> function f(var)
>>> {var$col1 <- ...
>>> var$col2 <- ...
>>> }
>>> 
>>> f(df1)
>>> 
>>> Each of the data frames have common column names
>>> 
>>> I would like for f to be able to perform operations on the data frames from
>>> within the function. I have tried testing variables without success. R
>>> allows for creating the necessary 'strings' with the correct names, however
>>> I am unable to bind, transform those strings to reference the data frames.
>> Learn to use "[[" instead of "$". (There is a warning about not doing what you are doing in the help page for ?"$" .)
>> 
>> And furthermore when you see this message (which Nabble rather impolitely removes)
>> "and provide commented, minimal, self-contained, reproducible code."  ... it means real R code and not pseudo-code as you are currently offering.
>> 
>> 
>> David Winsemius
>> Alameda, CA, USA
> 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list