Error message when using DataFrame()

Hi,
I am trying to convert the simulation object output to a data frame using DataFrame() function but I am receiving the following error
ERROR: DimensionMismatch(“array could not be broadcast to match destination”)
I would like to know how to interpret this error

Thanks

Hi Ahmed. If you have a minimal example that gives the error, we will be able to help you better.

Do you have time varying covariates, @ahmed.salem ?

Yes I have a time varying covariate. It seems that there was a bug when there is time varying covariate (from a previous post) and It should have been resolved in the next release of Pumas

1 Like

I have a PK dataset with the standard dosing and observations records such as: id, time, amt, conc, evid, cmt. My amt column is in mg. I am trying to create another amt column called amt_in_ug = amt * 1000. However, I get errors most likely because several amt rows are missing. how to handle such mathematical operations with columns with missing rows? This is a very frequent data formatting maneuver and unfortunately I could not find any info when I searched in google for julia code. The first link was to this Missing Values · The Julia Language but I could not find any answer to my a question similar to mine. Thank you.
Bob

1 Like

This looks like a new syntax from what I learned from the tutorials?
@rtransform pkdata @passmissing :amt_Bool=convert(Bool, :amt)
pkdata[!,:amt_in_ug] = pkdata.amt_Bool .* 1000

Is this how I perform my operation?
Bob

I am not sure what is your data formatting, syntax you use and the error you get but assuming the following example you should get the new column like this:

df= DataFrame(id = repeat([1],inner= 5),amt = [100,missing,missing,missing,missing])
df[!,:amt_2] = @. df[!,:AMT]*100
1 Like

@ahmed.salem thank you. I think I had a problem with ‘.’ (forgot to include).

However, the syntax that is provided in the tutorial and the above are different. One uses @transform etc; the above uses a format I am more used to. However, I did not realize I had to use ‘@.’. I have only used ‘@’ in the derived block after an ‘=’. Is there a preferred format?
Bob

So in above example you do not even need to do broadcasting which is adding “@.” like example below

df= DataFrame(id = repeat([1],5),amt = [100,missing,missing,missing,missing],factor = repeat([1000],5))
df[!,:amt_2] =  df[!,:amt]*100

But in case you want to multiply by another column (for example here I added 100 in a column called factor), you need to do broadcasting in one of two ways like the following

df= DataFrame(id = repeat([1],5),amt = [100,missing,missing,missing,missing],factor = repeat([1000],5))
df[!,:amt_2] = @. df[!,:amt]*df[!,:factor] #method 1
df[!,:amt_2] .=  df[!,:amt].*df[!,:factor] # method 2

My understanding is that adding “@.” will override adding “.” before every operation. Hope it is clearer

1 Like