Data Table Parsing Function - Intelligent VLOOKUP()

Data Table Parsing Function - Intelligent VLOOKUP() - Сообщения

#1 Опубликовано: 02.01.2017 21:33:38
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

I would like to share an example of function that extracts rows from a data table based on set value in selected columns:
VLOOKUPdataparse.sm (17 КиБ) скачан 70 раз(а).
vlookup1.png
vlookup2.png
2 пользователям понравился этот пост
Davide Carpi 03.01.2017 06:54:00, francesco rapuano 31.12.2024 00:37:00
#2 Опубликовано: 02.01.2017 21:39:38
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

I do need help with an interesting behaviour of a matrix definition:

If an element of a defined matrix contains a user defined function with an undefined parameter it may inthrow an error similar to here (same SMath file as above):

matrixBug_ElementContainsCustomFuction.png

I would expect the function with undefined parameter to return itself instead of giving an error code.
#3 Опубликовано: 03.01.2017 07:06:30
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: Moderator

Very nice

I think the issue comes out because there isn't a way to stop the preprocessing in user-defined functions when you pass an unknown (and an unknown is not a valid input).

A workaround that might be useful even to avoid the use of other functions is to use a string as input in the second row, and a check in your lookup like this:

2017-01-03 11_03_34-SMath Studio - [VLOOKUPdataparse.sm].png

2017-01-03 11_04_37-SMath Studio - [VLOOKUPdataparse.sm].png
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
2 пользователям понравился этот пост
frapuano 03.01.2017 10:44:00, Alexander O. Melnik 03.01.2017 08:45:00
#4 Опубликовано: 03.01.2017 09:06:46
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

Davide,

Is the a reason why function like findstr() does not return itself when not all variables are defined? Similar to this:
http://en.smath.info/forum/yaf_postsm36158_cases-in-definition-of-a-function.aspx#post36158

Also I am not sure if this is similar, but after I modified my excel_IO() function to return FALSE if undefined variables were present it would preprocess correctly with undefined variables when passed as an argument to a user defined function (you and I had an email discussion about this).

P.S.: the reason why a more general solution is desired is because a one might want to implement a more complex boolean check, than <>=!
#5 Опубликовано: 03.01.2017 12:37:22
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: Moderator

Wrote

Is the a reason why function like findstr() does not return itself when not all variables are defined? Similar to this:
http://en.smath.info/forum/yaf_postsm36158_cases-in-definition-of-a-function.aspx#post36158


It is by design. However even returning itself, you will have always var=findstr(...) -> false -> ... (it doesn't prevents the strcont() function to be evaluated)

Wrote

Also I am not sure if this is similar, but after I modified my excel_IO() function to return FALSE if undefined variables were present it would preprocess correctly with undefined variables when passed as an argument to a user defined function (you and I had an email discussion about this).


Yes, but with functions created on the canvas this isn't possible

Wrote

P.S.: the reason why a more general solution is desired is because a one might want to implement a more complex boolean check, than <>=!


You can try with this:
2017-01-03 16_36_25-SMath Studio - [VLOOKUPdataparse(1).sm_].png

strcont() is defined locally to avoid the preprocessing on the canvas
try() function is added because when you use el(...) inside the lookup function, all the elements of the condition matrix are evaluated -> you have to allow any type of input as first argument or let it fails silently (because strrep requires strings); note that if the selected element of the condition matrix is the one that contains strcon() with a wrong type as first argument, the error string will trigger an error on bool#:eval(bool#*operand#), because operand# will be a string.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
2 пользователям понравился этот пост
Alexander O. Melnik 03.01.2017 12:41:00, frapuano 03.01.2017 14:55:00
#6 Опубликовано: 03.01.2017 15:06:28
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Alex,

The attached proposal is for fixed "credit".
It might be ranged via bolean.

Jean

Alex VLOOKUPdataparse.sm (33 КиБ) скачан 64 раз(а).
1 пользователям понравился этот пост
Alexander O. Melnik 03.01.2017 15:37:00
#7 Опубликовано: 03.01.2017 15:37:30
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

Wrote

Alex,

The attached proposal is for fixed "credit".
It might be ranged via bolean.

Jean

Alex VLOOKUPdataparse.sm (33 КиБ) скачан 64 раз(а).




Thanks, Jean. I havent used "truth tables" yet; they seem to work quite well.
#8 Опубликовано: 06.01.2017 20:53:23
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

Is there a quicker way to assemble a SMath matrix from rows than stack()?

In vb.net I can assemble 13x10000 SMath matrix in 3.3 seconds (excel_OUT), while stacking of 488 rows (13 elements each) into matrix within SMath takes 21 seconds

Thanks!
#9 Опубликовано: 09.01.2017 07:49:47
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: Moderator

Wrote

while stacking of 488 rows (13 elements each) into matrix within SMath takes 21 seconds



Hello Alex, can you attach an example where stack it is so slow?
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#10 Опубликовано: 09.01.2017 10:31:18
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Alex,

It depends what you assemble, and how.
Three examples attached.

Jean

Alex Assemble Matrix.sm (32 КиБ) скачан 49 раз(а).
#11 Опубликовано: 09.01.2017 13:52:25
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

Wrote

Wrote

while stacking of 488 rows (13 elements each) into matrix within SMath takes 21 seconds



Hello Alex, can you attach an example where stack it is so slow?



Here it is - I use EXCEL to input 10000 x 13 matrix into SMATH - 1.2 seconds. Vlookup() loop to stack 400 rows - 15 seconds. Vlookup() loop which does not stack anything is 3 seconds.

VLOOKUPslow.sm (27 КиБ) скачан 54 раз(а).
DATA.xlsx (1 МиБ) скачан 69 раз(а).
#12 Опубликовано: 09.01.2017 21:06:51
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: Moderator

Try this; basically removes all stack() calls to build the matrix after you check all the conditions. On my notebook is 50% faster than your.

VLOOKUPfast.sm (31 КиБ) скачан 124 раз(а).
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
1 пользователям понравился этот пост
Alexander O. Melnik 09.01.2017 21:14:00
#13 Опубликовано: 09.01.2017 21:13:40
Alexander O. Melnik

Alexander O. Melnik

127 сообщений из 494 понравились пользователям.

Группа: Moderator

Wrote

Try this; basically removes all stack() calls to build the matrix after you check all the conditions. On my notebook is 50% faster than your.

VLOOKUPfast.sm (31 КиБ) скачан 124 раз(а).



Much better, thanks.

Could you explain how does the following exactly work:

resultrng#:el(data#,matches,range(1,cols(data#)))
#14 Опубликовано: 09.01.2017 21:32:49
Davide Carpi

Davide Carpi

1416 сообщений из 2873 понравились пользователям.

Группа: Moderator

Wrote

Much better, thanks.

Could you explain how does the following exactly work:

resultrng#:el(data#,matches,range(1,cols(data#)))



You're welcome

It is this feature; in the 2nd argument of el(3) there are all the rows I want from first argument's matrix, as 3rd argument all the columns. The result is a matrix of the elements that fits both the requirements, in the given order.
If you like my plugins please consider to support the program buying a license; for personal contributions to me: paypal.me/dcprojects
#15 Опубликовано: 23.04.2021 00:20:54
xsynt

xsynt

0 сообщений из 1 понравились пользователям.

Группа: User

thank you for sharing these function, lookup is another essential features of spreadsheet and could be better if it has to be include in standard distribution.

from vlookupfast.sm modification, may it be simplified for such a situation below. in case condition only use boolean 'equal to' as the same in any spreadsheet function.

vlookupsimplified.png
#16 Опубликовано: 23.04.2021 15:29:41
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

Wrote

lookup is another essential features of spreadsheet and could be better if it has to be include in standard distribution.


There area dozen of lookup. If so many for so many applications.
Be more specific c/w *.sm document.

Lookup.PNG
#17 Опубликовано: 23.04.2021 15:36:59
Jean Giraud

Jean Giraud

983 сообщений из 6866 понравились пользователям.

Группа: User

... visit this intelligent/advanced lookup.

Utilities Matrix Locate Array1 Array2.sm (70 КиБ) скачан 62 раз(а).
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений