Search code examples
rdataframeoutliersrbindcbind

Error in Dataframe : arguments implying different number of arguments


my data frame had many outliers in each column / variable. I removed them using Boxplot / IQR cut-off for 75% / 25%. I took out each column and removed outliers from them. Therefore, each column has different number of values in it. Now I want to combine those all NEW variables which does not has any outlier in it to single data frame. I am getting this error in Data frame. How do I solve this problem? Because, I have to perform logistic regression on that NEW data frame. I tried cbind.data.frame and then similar with rbind, but that is not solving the issue.

Here is the code:

newdata <- data.frame(finalsbp, mynewT, mynewldl,mynewtypea1, mynewobesity, mynewalcohol, age, famhist)

Error in data.frame(finalsbp, mynewT, mynewldl, mynewtypea1, mynewobesity,  : 

arguments imply differing number of rows: 447, 443, 448, 458, 454, 429, 462

P.S. Length of age and famhist is same. i.e. 462


Solution

  • Without knowing more about your data, you could try to just make each vector the same length like this as indicated in this post.

    a <- seq(from = 1, to = 10)
    b <- seq(15, 30)
    c <- seq(2, 10)
    
    length(a) <- n
    length(b) <- n
    length(c) <- n
    
    newdata <- cbind(a, b, c)
    

    This should solve your problem, assuming you want all the blanks to appear as NA at the end of the data frame.