Using arrays to compare user provided values - arrays
So I have 3 user-provided values, the first is their "total_income", the second value is either "part_time" or "full_time", and the last value is "family_size".
I'm trying to write code in LUA that takes these values and evaluates them to assign a value called "fee".
I have an excel file that gives me "fee" values for both "full_time" and "part_time", and those depend upon what "total_income" is entered.
The problem I am having is, I don't know how to incorporate the user's provided values of "part_time" and "family_size"
I hope this makes sense, if not please don't hesitate to email me at ochow0401#gmail.com, or PM me here. Any help would be highly appreciated.
Whoever can steer me in the right direction first, gets lunch on me ;)
I was able to successfully compare the user-provided "total_income" against the excel file to see where it falls in the income range. Based on this index I am able to see what "fee" value to assign. The code I provided below successfully sets the "fee" for the users "total_income", but how would I do a check for whether the user inputted "part_time" or "full_time" within a loop?
part_time_fee = 0
full_time_fee = 0
part_time = {31,38,45,53,68,76,85,94,104,113,123,134,145,156,159,161,164,167,178,181,184,187,190,193,196,199,203,206,209,212,215,218,221,227,234,240,246,252,259,265
}
full_time = {61,75,90,106,135,152,170,207,226,246,267,289,311,317,322,328,334,355,361,367,373,380,386,392,398,405,411,417,423,429,436,442,454,467,479,492,504,517,529
}
family_size_1_or_2 = {2451,2514,2577,2640,2703,2766,2829,2892,2955,3017,3080,3143,3206,3269,3332,3395,3457,3520,3583,3646,3709,3772,3835,3897,3960,4023,4086,4149,4212,4275,4337,4400,4463,4589,4715,4840,4966,5092,5218,5343
}
for i = 1, 40, 1
do
if family_size_1_or_2[i] >= answers.calc_total_income then
answers.fam_fee = part_time[i]
break
end
end
https://imgur.com/SHHqC2L
That is the first 15 rows of the excel sheet I was provided.
I am to take the users inputs, "total_income", "family_size", and "part_time" or "full_time". Then I am to give it it's corresponding "fee" value.
So if a user were to enter these values:
total_income = 3000
family_size = 2
full_time
then
fee = 226
Related
Can anybody help be with immediate less than and immediate greater than from a number query in solr
var strQuery = client_education.query().q( 'all_type:current_affairs AND active:1 AND ca_id:123) var next = client_education.query().q( 'all_type:current_affairs AND active:1 AND ca_id>123) // should return the greater than 123 ca_id from database // var previous = client_education.query().q( 'all_type:current_affairs AND active:1 AND ca_id<123) // should return the less than 123 ca_id from database How can I retrieve values greater than and less than the given id (123) in solr?
Range searches can be done using [start TO end], where [] is used to mean including, while {} is used to mean excluding the start/end. For any value larger than 123: ca_id:{123 TO *] For any value smaller than 123 (not including): ca_id:[* TO 123} This assume that your fields are configured as proper integer fields. If you have configured them a text or string fields, this won't work (and you need to reconfigure them), since 111111 sorts before 123 and thus is considered less than 123. But as long as you've configured your fields as numeric / integer fields, the range syntax works as expected.
SAS- setting missings to a range of columns based on the value of another variable
I currently have a dataset that includes an ID for each person, and then variables called day1 through day1826 that are binary indicators of availability of a drug on each of those days. I need to censor individuals on certain days. For example, if a person needs to be censored on day500, then I need day500 to be set to missing, as well as every day variable after that (i.e. day500 through day1826). I have a variable called time_for_censor that indicates what day to start the missings. How can I code this in SAS? I've tried to code it in a loop like this: array daydummy (1826) day1-day1826; if time_for_censor ne . then do time_for_censor=1 to 1825; daydummy(time_for_censor)=.; daydummy(time_for_censor + 1) =.; end;
Just loop from the censor date to the end of the array. array daydummy (1826) day1-day1826; if not missing(time_for_censor) then do index=time_for_censor to 1826; daydummy(index)=.; end; drop index; You might need to change the lower bound on the do loop to time_for_censor+1 depending on the whether the values are valid on the censoring date or not.
Compare and divide in report builder
I have a condition I want to divide two values in report builder with same date but different sample name in the same table... For example, in this image, I want to divide the CM2(2.85) and Raw Meal(0.58) value. their result should be 4.9. And if these two parameters (CM2 and Raw Meal) are not on the same date then the value should be empty or nothing. Please help I am new to report builder expression. I've tried this expression but it does not give me what I need IIf(InStr(Fields!Sample_Code.Value,"CM2") > 0, Fields!So3.Value, nothing) / IIf(InStr(Fields!Sample_Code.Value,"Raw Meal") > 0, Fields!So3.Value, nothing)
The record will either be CM2 or Raw Meal, but it will never contain both at the same time. If Fields!Sample_Code.Value = "CM2" is true, the second half of the expression will be false, or vice-versa. Fields!Sample_Code.Value can't be two different values at the same time, it can only contain the data from a single record. Your expression will result in either: nothing/Fields!So3.Value or Fields!So3.Value/nothing. As a simplified example: IF( x=1 , 1 , null) / IF( x=2 , 1 , null) X cannot be two different values at the same time so the expression will never return a non-null result. You'll need to join CM2 and RAW MEAL records together to evaluate them at the same time. That would probably require a significant change to what you've posted so far.
Link two tables based on conditions in matlab
I am using matlab to prepare my dataset in order to run it in certain data mining models and I am facing an issue with linking the data between two of my tables. So, I have two tables, A and B, which contain sequential recordings of certain values in a certain timestamps and I want to create a third table, C, in which I will add columns of both A and B in the same rows according to some conditions. Tables A and B don't have the same amount of rows (A has more measurements) but they both have two columns: 1st column: time of the recording (hh:mm:ss) and 2nd column: recorded value in that time Columns of A and B are going to be added in table C when all the following conditions stand: The time difference between A and B is more than 3 sec but less than 5 sec The recorded value of A is the 40% - 50% of the recorded value of B. Any help would be greatly appreciated.
For the first condition you need something like [row,col,val]=find((A(:,1)-B(:,1))>2sec && (A(:,1)-B(:,1))<5sec) where you do need to use datenum or equivalent to transform your timestamps. For the second condition this works the same, use [row,col,val]=find(A(:,2)>0.4*B(:,2) && A(:,2)<0.5*B(:,2) datenum allows you to transform your arrays, so do that first: A(:,1) = datenum(A(:,1)); B(:,1) = datenum(B(:,1)); you might need to check the documentation on datenum, regarding the format your string is in. time1 = [datenum([0 0 0 0 0 3]) datenum([0 0 0 0 0 3])]; creates the datenums for 3 and 5 seconds. All combined: A(:,1) = datenum(A(:,1)); B(:,1) = datenum(B(:,1)); time1 = [datenum([0 0 0 0 0 3]) datenum([0 0 0 0 0 3])]; [row1,col1,val1]=find((A(:,1)-B(:,1))>time1(1)&& (A(:,1)-B(:,1))<time1(2)); [row2,col2,val2]=find(A(:,2)>0.4*B(:,2) && A(:,2)<0.5*B(:,2); The variables of row and col you might not need when you want only the values though. val1 contains the values of condition 1, val2 of condition 2. If you want both conditions to be valid at the same time, use both in the find command: [row3,col3,val3]=find((A(:,1)-B(:,1))>time1(1)&& ... (A(:,1)-B(:,1))<time1(2) && A(:,2)>0.4*B(:,2)... && A(:,2)<0.5*B(:,2); The actual adding of your two arrays based on the conditions: C = A(row3,2)+B(row3,2);
Thank you for your response and help! However for the time I followed a different approach by converting hh:mm:ss to seconds that will make the comparison easier later on: dv1 = datevec(A, 'dd.mm.yyyy HH:MM:SS.FFF '); secs = [3600,60,1]; dv1(:,6) = floor(dv1(:,6)); timestamp = dv1(:,4:6)*secs.'; Now I am working on combining both time and weight conditions in a piece of code that will run. Should I use an if condition inside a for loop or is a for loop not necessary?
Different results from STRREAD() for reading strings
I have a date cell array which is read from a csv file. The format is below: date = '2008.12.01' '2008.12.02' '2008.12.03' '2008.12.04' '2008.12.05' ... ... And I want to: turn the cell array to a string array, use the strread() to read its "yyyy","mm" and "dd" value into 3 double array [year,mm,dd], use the datenummx() to turn [year,mm,dd] into date seriel num. After i use date = char(date); the date array become like this: date = 2008.12.01 2008.12.02 2008.12.03 2008.12.04 2008.12.05 ... ... which I think the result is what i want... But after I use the strread(), it gives me odd result. [year,month,day]=strread(date,'%d%d%d','delimiter','.'); year = -1 0 0 0 0 ... ... BUT if I use the code below, the strread() can give me the right answer: s = sprintf('2008.12.01') s = 2008.12.01 [year,month,day]=strread(s,'%d%d%d','delimiter','.') year = 2008 month = 12 day = 1 And I checked in the matlab that both the "date" and "s" is a char array.(by using function 'ischar' and simply display both)... But why do the strread() give differnt results? Can anyone answer? by the way, I use the MatLab v6.5.(for my own reason, so please don't comment by asking "why not use a higher version")....
Your problem is this line: date = char(date); It does not create an array of strings, there is no array of strings in matlab. It creates an array of chars. As you already noticed, your strread-line is fine if you input a single date, so input each date form your original cell array individually: for idx=1:numel(date) [year(idx),month(idx),day(idx)]=strread(date{idx},'%d%d%d','delimiter','.'); end Preallocation of year, month and day improves the performance.