How to fix error variable lengths differ?

Hi guys, I know what the error means but have no clue how to fix this. Im going quite mental at this point. So basically I want to run a simple regression.

total.rev <- CompustatPharma$Revenue total - Y[!is.na(CompustatPharma$Revenue total - Y)]
cap.ex <- CompustatPharma$Capital expenditure - Y[!is.na(CompustatPharma$Capital expenditure - Y)]
SGA.exp <- CompustatPharma$SG&A expense - Y[!is.na(CompustatPharma$SG&A expense - Y)]

EBITDA <- total.rev - cap.ex - SGA.exp
summary(EBITDA)

equity.total <- CompustatPharma$Common - Ordinary Equity Total - Q[!is.na(CompustatPharma$Common - Ordinary Equity Total - Q)]
debt.total <- CompustatPharma$Long term debt total - Q[!is.na(CompustatPharma$Long term debt total - Q)]
cash <- CompustatPharma$Cash - Q[!is.na(CompustatPharma$Cash - Q)]

firm.value <- ((equity.total + debt.total - cash) / EBITDA)
summary(firm.value)

regmod <- lm(firm.value ~ working.capital)

My firm value is numeric with 1:5550 and working capital numeric with 1:5286

Hopefully someone can help me :slight_smile:

Hi, the purpose of dataframes is to keep related data together, I would characterise your workflow as vector based. This is a direct cause of your difficulty as you are violating the relationships between variables by omitting na.s for some in a way that others are not affected....

Either deal with na.s upfront by omitting them from your dataframe as a whole. (Use na.omit)
Or learn to use tidyverse/dplyr style transformations which facilitate a dataframe level workflow.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.

CompustatPharma_nona <- na.omit(CompustatPharma)
1 Like

Hi thanks for the quick answer! How should I use na.omit upfront? Like any specific formula?

I guess firm.value will be infinite if Ebidta is zero
Do you have such cases ?

First of all, thank you so much. Now it all has the same vector lengths however, i still can't run my regression is i receive a new error: Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) :
NA/NaN/Inf in 'y'

Yes indeed I have such cases, makes sense actually. How can I compute this in such way that EBITDA is not negative?