[R] Advanced R: manipulating lists, asking a help with programming

Kaja minar.jana at gmail.com
Thu Jan 22 17:50:40 CET 2015


my question is about a specific problem concerning programming R for that I
have not found a solution since 2 weeks (I have seen forums, searched on
google, all).

The main goal is to remove overlaping events. I have two equal lists of 10
dataframes each (number of rows of these 10 dataframes is varying): in one
are values (list.n) and in another corresponding Dates (list.perc), each
column represents one station (the same stations are in all 10 dataframes
of a list, identically ranked, number of rows is about 20.000); NA values
if any are in the end of columns.

I would like to create a program, a loop such as:
telling the program find me a maximum value for a station (for a given
column) iSta over the list.n. This value N has to be conserved. Create a
variable D==dataframes position in list.n (i.e. list.n[[D]]). Search the
same position over the list.perc (for column iSta), the corresponding
date==X (new variable that has also to be stocked). Make all dates(in
list.perc) and corresponding values (in list.n) "NA" (or remove them
directly) that are inside (or equal) the following interval (with exeption
of N and X that have to be conserved):
{X-D'+1,X+D-1+D'-1} for D' from 1 to 10  corresponding to the searching
dataframes position (e.g., if searching in list.perc[[3]], D'==3)
Then search the second maximum over list.n for the given station iSta etc.
until the last remaining value of iSta over list.n and list.perc
respectively. Do this for all iSta stations.
The result may be a simplified list from that I will extract only not NA

Can someone help me?

May be there is a package that can do this. I have at least found this
logic of proceeding and then try all like lapply and sapply function for
searching maximum and its index for iSta across list, but I am not able to
find suitable commands to do this task across lists and in the best not
much time consuming way.

May be I have to try with 3D matrix?

Thanks a lot for any idea!
I send you a short example of my Data with only 2 (instead of 10)
dataframes in a list that has to be arrandes as follows:

> list.n<-vector("list",2)
> list.perc<-vector("list",2)
> list.n[[1]]<-n1
> list.n[[2]]<-n2
> list.perc[[1]]<-perc1
> list.perc[[2]]<-perc2
> list.perc
> list.n

Best regards,

list_N2.txt (1K) <http://r.789695.n4.nabble.com/attachment/4702132/0/list_N2.txt>
list_Perc1.txt (1K) <http://r.789695.n4.nabble.com/attachment/4702132/1/list_Perc1.txt>
list_Perc2.txt (1K) <http://r.789695.n4.nabble.com/attachment/4702132/2/list_Perc2.txt>
list_N1.txt (1K) <http://r.789695.n4.nabble.com/attachment/4702132/3/list_N1.txt>

View this message in context: http://r.789695.n4.nabble.com/Advanced-R-manipulating-lists-asking-a-help-with-programming-tp4702132.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]

More information about the R-help mailing list