I know how to define replacement functions in R (i.e. ‘foo<-‘ <- 
function(x,value) x<-value, etc.), but how do you define replacement functions 
that operate on subsets of arrays (i.e. how do you pass an index into foo)?
For example, why does the following use of “rownames” work?

> aa <- data.frame( a=1:10,b=101:110 )

> aa

    a   b

1   1 101

2   2 102

3   3 103

4   4 104

5   5 105

6   6 106

7   7 107

8   8 108

9   9 109

10 10 110

> rownames(aa)[2:4] <- c('row2','row3','row4')

> aa

      a   b

1     1 101

row2  2 102

row3  3 103

row4  4 104

5     5 105

6     6 106

7     7 107

8     8 108

9     9 109

10   10 110

> 

 

Thanks,

Harry

 
        [[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.

Reply via email to