[R] Multiply list objects

Uwe Ligges ligges at statistik.tu-dortmund.de
Fri Jun 17 11:14:56 CEST 2011


Since this example is not reproducible (and you have not quuoted any 
former code) I can only give advice "in principle":

1. Never use 1:length(x) since this will seriously fail if x is a length 
0 object. Instead, use seq_along(x)
2. If k is a list, then you probably want to use doubled brackets in 
k[[year]] for a scalar valued "year".

Uwe Ligges



On 16.06.2011 23:49, mdvaan wrote:
> I am still thinking about this problem. The solution could look something
> like this (it's net yet working):
>
> k<-lapply(h, function (x) x*0) # I keep the same format as h, but set all
> values to 0
> years<-c(1997:1999) # I define the years
> for (t in 1:length(years))
> 	{
> 	year = as.character(years[t])
> 	ids = rownames(h[year][[1]])
> 	}
> 	for (m in 1:length(relevant_firms))
> 		{
> 		k[year][[m]]<-lapply(k[year], function (col) k[year][[1]][,m] =
> h[year][[1]][,m]&  k[year][[1]][m,] = h[year][[1]][m,])
> 		} # I am creating new list objects that should look like this
> k$'1999'$'8029' and I replace the values in the 8029 column and row by the
> original ones in h
>
> Any takes on this problem? Thank you very much!
>
> Best
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Multiply-list-objects-tp3595719p3603871.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.



More information about the R-help mailing list