# Remove one element within a nested list or create lists of equal length

Posted 14 days ago
205 Views
|
6 Replies
|
1 Total Likes
|
 port = {"^GSPC", "GLD", "VCSH"}; ret1 = QuantityMagnitude[ FinancialData[#, "Return", {2021}]["Values"]] & /@ port; In[120]:= Length[#] & /@ {ret1[[1]], ret1[[2]], ret1[[3]]} Out[120]= {169, 168, 168} I have three sub-lists of unequal length. How could I remove, say the first element in the first list?? I have tried Drop without success. Better yet, how would I create the three lists of equal length in the first place???Thanks much for the help.
6 Replies
Sort By:
Posted 14 days ago
 Perhaps lists={{1,2,3},{4,5,6,7},{8,9}}; minlen=Min@@Map[Length,lists]; res=Map[Take[#,minlen]&,lists] which returns {{1,2},{4,5},{8,9}} 
Posted 14 days ago
 Excellent job Bill I had manually removed the first element from the first list because it was the easiest. I did a correlation test between the first list and the next two lists. My method resulted in a correlation near zero for list 1 related to lists 2 & 3. The data is time stamped, I just removed the time stamp for easier computations. I then used your method that basically removes the last element in the list. I was quite surprised to find a correlation of 30% between list 1 with both lists 2 & 3. There are 168 elements in each of the three lists, it was quite surprising to find such a difference between either removing the first versus removing the last element. Thanks so much for your help.
Posted 13 days ago
 "Surprising" and "such a difference from such a small change" always makes me think "I've made a mistake in this somehow."Perhaps the time stamps might be too important to discard. Is there any way you could do a ListPlot with the time stamps and another without the time stamps and see if the reason for the large change becomes obvious? If that explains things then would interpolating the {value,time} points to construct value=function[time] still make your computations easy
Posted 13 days ago
 Hi Bill The correlations between no deletion and 1 day deletion I plotted the graphs, but Return is the % change in price from the day before, so the charts just looks like noise.I did average the Return, which did reduce the error caused by the one day deletion. Below is the Notebook
 I peeked at one of the three using port = {"^GSPC", "GLD", "VCSH"}; ret1 = FinancialData[#, "Return", {2021}] & /@ port; FullForm[ret1[[1]]] and that gives some functions that can be looked up in the help system.It appears that the data might already be the result of interpolation and there don't seem to be any time stamps associated with individual data values. If that is the case then I don't understand how it is possible that you are getting different numbers of data points sometimes or why dropping extra items would make such a difference.At this point I'm guessing to go back to the source of this data or the source of the processing and ask for an explanation.
 Take a look at the documentation for Rest and Most. FinancialData returns a TimeSeries. There are many functions available for time-series processing. For time-series correlation, take a look at this post on MSE and this one on this site.