R-help, I have a list whose elements are data frames. I want to change the colnames attribute in each element of this list but an error message comes up:> lapply(LD_strataNew,function(x) dimnames(x)[[2]][-1]) <- as.roman(1:9)[-6]Error in lapply(LD_strataNew, function(x) dimnames(x)[[2]][-1]) <- as.roman(1:9)[-6] : could not find function "lapply<-"> lapply(LD_strataNew,function(x) dimnames(x)[[2]])$`1996` [1] "lgdcm" "X1" "X2" "X3" "X4" "X5" "X7" "X8" "X9" $`1997` [1] "lgdcm" "X1" "X2" "X3" "X4" "X5" "X7" "X8" "X9" $`1998` [1] "lgdcm" "X1" "X2" "X3" "X4" "X5" "X7" "X8" "X9" ....... ....... ....... Why does it not work? Thanks in advance.
You can try this instead: lapply(LD_strataNew, 'colnames<-', as.character(as.roman(1:9)[-6])) On Tue, Dec 8, 2009 at 9:38 AM, Luis Ridao Cruz <Luisr at hav.fo> wrote:> R-help, > > I have a list whose elements are data frames. > I want to change the colnames attribute in each element of this list but an error message > comes up: > >> lapply(LD_strataNew,function(x) dimnames(x)[[2]][-1]) <- as.roman(1:9)[-6] > Error in lapply(LD_strataNew, function(x) dimnames(x)[[2]][-1]) <- as.roman(1:9)[-6] : > ?could not find function "lapply<-" > > >> lapply(LD_strataNew,function(x) dimnames(x)[[2]]) > $`1996` > [1] "lgdcm" "X1" ? ?"X2" ? ?"X3" ? ?"X4" ? ?"X5" ? ?"X7" ? ?"X8" ? ?"X9" > > $`1997` > [1] "lgdcm" "X1" ? ?"X2" ? ?"X3" ? ?"X4" ? ?"X5" ? ?"X7" ? ?"X8" ? ?"X9" > > $`1998` > [1] "lgdcm" "X1" ? ?"X2" ? ?"X3" ? ?"X4" ? ?"X5" ? ?"X7" ? ?"X8" ? ?"X9" > > ....... > ....... > ....... > > Why does it not work? > > Thanks in advance. > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Hi Luis, You can't assign to lapply. --Gray On Tue, Dec 8, 2009 at 5:38 AM, Luis Ridao Cruz <Luisr at hav.fo> wrote:> R-help, > > I have a list whose elements are data frames. > I want to change the colnames attribute in each element of this list but an error message > comes up: > >> lapply(LD_strataNew,function(x) dimnames(x)[[2]][-1]) <- as.roman(1:9)[-6] > Error in lapply(LD_strataNew, function(x) dimnames(x)[[2]][-1]) <- as.roman(1:9)[-6] : > ?could not find function "lapply<-" > > >> lapply(LD_strataNew,function(x) dimnames(x)[[2]]) > $`1996` > [1] "lgdcm" "X1" ? ?"X2" ? ?"X3" ? ?"X4" ? ?"X5" ? ?"X7" ? ?"X8" ? ?"X9" > > $`1997` > [1] "lgdcm" "X1" ? ?"X2" ? ?"X3" ? ?"X4" ? ?"X5" ? ?"X7" ? ?"X8" ? ?"X9" > > $`1998` > [1] "lgdcm" "X1" ? ?"X2" ? ?"X3" ? ?"X4" ? ?"X5" ? ?"X7" ? ?"X8" ? ?"X9" > > ....... > ....... > ....... > > Why does it not work? > > Thanks in advance. > > ______________________________________________ > 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. >-- Gray Calhoun Assistant Professor of Economics Iowa State University