I found this code on GitHub for simulating covid data in Rstudio but I am unable to get it to run. The following lines
# calculate how much infectiousness arises from all teachers (t_bI) and all pupils (p_bI)
sim$t_bI[d_iter] = sum(as.vector(sim[d_iter,paste0("t_I_",seq(1,15,1))]*infectiousness_over_time))
sim$p_bI[d_iter] = sum(as.vector(sim[d_iter,paste0("p_I_",seq(1,15,1))]*infectiousness_over_time_child))
return this error
Error in sum(as.vector(sim[d_iter, paste0("t_I_", seq(1, 15, 1))] * infectiousness_over_time)) :
invalid 'type' (list) of argument
I won't paste the entire code here but it is available at
https://github.com/annabershteyn/ACTA_Dx/blob/main/school_sim_R/simulate_school_transm.R
Thanks so much for any help!
Comparing two xml files in soapui using groovy with XMLUnit2, Have some weird cases which are different in both files, but are acceptable. So have to ignore/skip those.
ResXML1:
<alpha:Errors>
<alpha:Error ShortText="SHiff" Type="11">Generic error occured.</alpha:Error>
<alpha:Error ShortText="SHiff" Type="12">Generic error occured.</alpha:Error>
</alpha:Errors>
<ShiftAttributes>
<ShiftAttribute ShiftAttributeCode="41"/>
<ShiftAttribute ShiftAttributeCode="17"/>
</ShiftAttributes>
<alpha:PriceInfo AgeQualifyingCode="10" Amount="19999.00" DiscountTypes="3" AMZAmount="225.00" NetAmount="19999.00" MCH="1" ValueAddAmount="150.00"/>
ResXML2:
<alpha:Warnings>
<alpha:Warning ShortText="SHiff" Type="11">Generic error occurred.</alpha:Warning>
</alpha:Warnings>
<ShiftAttributes>
<ShiftAttribute ShiftAttributeCode="17"/>
<ShiftAttribute ShiftAttributeCode="41"/>
</ShiftAttributes>
<alpha:PriceInfo AgeQualifyingCode="10" Amount="19999.0" DiscountTypes="3" AMZAmount="225.0" NetAmount="19999.0" MCH="1" ValueAddAmount="150.0"/>
If anyone have any idea, please help me in below conditions.
1) How to ignore child attribute order? tried different nodematchers(byXpath, byNameandText etc..), but no luck.
<ShiftAttribute ShiftAttributeCode="41"/>
<ShiftAttribute ShiftAttributeCode="17"/>
2) How to ignore decimal value, 100.0 & 100.00. Tried to use BigDecimalElementDifferenceEvaluator, but cannot able to complete in soapui. If we have any easy method please help me?
Found solution for first part of the above question
diff = DiffBuilder.compare(ResXML1).withTest(ResXML2)
.withNodeMatcher(
new DefaultNodeMatcher(
ElementSelectors.conditionalBuilder()
.whenElementIsNamed("ShiftAttribute")
.thenUse( ElementSelectors.byNameAndAttributes("ShiftAttributeCode"))
.elseUse(ElementSelectors.byName)
.build()
)
).build();
I'd like to concat or merge or append/join two csv files with the same indix ID but different extensions on the same ID. The data are grouped by ID also. The 1st file looks like this:
ID,year,age
810006862,2000,49
810006862,2001,
810006862,2002,
810006862,2003,52
810023112,2003,27
810023112,2004,28
810023112,2005,29
810023112,2006,30
810033622,2000,24
810033622,2001,25
and the 2nd file looks like this:
ID,year,from1,to1
810006862,2002,15341,15705
810006862,2003,15706,16070
810006862,2004,16071,16436
810006862,2005,,
810023112,2000,14610,14975
810023112,2001,14976,15340
810023112,2003,15825,16523
810033622,2000,13211,14876
810033622,2001,14761,14987
I have set index of ID for both files after reading it to dataframe, and then concat them together, but it gets error message of "ValueError: Shape of passed values is (25, 2914), indices imply (25, 251)"
I've tried the following codes:
sp = pd.read_csv('sp1.csv')
sp = sp.set_index('ID')
op = pd.read_csv('op1.csv')
op = op.set_index('ID')
ff = pd.concat([sp, op], join = 'outer', sort = False, axis = 1)
I've also tried concat the two files together without setting up index, and the result seemed having correct rows, but the horizontal values were incorrect related.
I've also tried merge as well, but it came with many unnecessary duplicated rows within each group. Since each group has different year and age, I found quite difficult to delete those newly generated rows using this method.
full = pd.merge(sp, op, on = 'ID', how = 'outer', sort = False)
Maybe somebody can suggest ways to easily delete these duplicates, and this will also work for me, because the merged file became so huge! Thanks in advance!
Expected results would be including all different values from both csv files. It is somewhat like this:
ID,year,age,from1,to1
810006862,2000,49,,
810006862,2001,,,
810006862,2002,,15341,15705
810006862,2003,52,15706,16070
810006862,2004,,16071,16436
810006862,2005,,,
810023112,2000,,14610,14975
810023112,2001,,14976,15340
810023112,2003,27,15825,16523
810023112,2004,28,,
810023112,2005,29,,
810023112,2006,30,,
810033622,2000,24,13211,14876
810033622,2001,25,14761,14987
I've searched online for similar posts along for quite some time, but unable to solve my problem. Can anybody offer any clue how to do this? Thanks a lot!
I'm trying to run a query on access using two live CSVs which has a common field with different data types(numbers and short text). I've discovered that you can join different data types using 'CStr'. I've added the 'CStr' to my code on the sql view. Please find the see the code below.
This gives me the output i want on access and i can now see the output when i click on 'datasheet view'. However, when i try to export the data (i'm actually trying create a export specification so that i can export a csv using macro) as a csv i'm getting a 'type mismatch in expression' error message.
Here's my code:
SELECT Sixthform_Reg_Year_Groups.Forename,
Sixthform_Reg_Year_Groups.Surname,
Sixthform_Reg_Year_Groups.Reg, Students.objectGUID
FROM Sixthform_Reg_Year_Groups INNER JOIN
Students
ON CStr(Sixthform_Reg_Year_Groups.Person_id) = Students.employeeID
WHERE (((Sixthform_Reg_Year_Groups.Reg)="12E"));`
I've also tried adding 'CStr' on both sides. as below, but experiencing the same issue.
FROM Sixthform_Reg_Year_Groups INNER JOIN
Students
ON CStr(Sixthform_Reg_Year_Groups.Person_id) = CStr (Students.employeeID)
WHERE (((Sixthform_Reg_Year_Groups.Reg) = "12E"));`
And of course, without 'CStr' i can't even view the output on 'datasheet view'. Every time when i click on datasheet view it's giving me the 'type mismatch in expression' error message.
Any help in resolving this would be much appreciated.
Thanks in advance.
Additinal info: the data types are EmpoyeeID is 'Short Text' and Person ID is 'Number'
Try the other way round:
ON Sixthform_Reg_Year_Groups.Person_id = Val(Students.employeeID)
and/or prevent Null errors:
ON CStr(Nz(Sixthform_Reg_Year_Groups.Person_id, 0)) = Nz(Students.employeeID)
OK guys, I've managed to resolve this issue, It turned out to be simple in the end. This is what i did.
Basically, I re imported the linked table. This time on the import window i clicked on 'advanced' and changed the data type to 'short text' on the 'person ID' column to match with the 'employeeID' data type. And then all problems solved. (I didn't know you could do this)
Thank you all for your replies. Going through your comments guided me to the right path.
Much appreciated.
I'm trying to save a R dataframe back to a sql database with the following code:
channel <- odbcConnect("db")
sqlSave(db, new_data, '[mydb].[dbo].mytable', fast=T, rownames=F, append=TRUE)
However, this returns the error "table not found on channel", while simultaneously creating an empty table with column names. Rerunning the code returns the error "There is already an object named 'mytable' in the database". This continues in a loop - can someone spot the error?
Is this about what your data set looks like?
MemberNum x t.x T.cal m.x T.star h.x h.m.x e.trans e.spend
1 2.910165e+12 0 0 205 8.77 52 0 0 0.0449161
I've had this exact problem a few times. It has nothing to do with a table not being found on the channel. From my experience, sqlSave has trouble with dates and scientific notation. Try converting x to a factor:
new_data$x = as.factor(new_data$x)
and then sqlSave. If that doesn't work, try as.numeric and even as.character (even though this isn't the format that you want.
As a first shot try to run sqlTables(db) to check the tables in the db and their correct names.
You could then potentially use this functions return values as the input to sqlSave(...)
It seems you are trying to write to a SQL Server. If you specify the database name in the ODBC connection, and then refer to the table as "dbo.mytable" it might help.
I could do it changing the connection in the driver odbc. When you open it, you can do it for one db or in general for all dbs. When you opened it for one db, you will not have a problem with sqlSave().