How to find the rows with maximum number of variables columnwise r -
i have data frame has thousands of rows , 25 columns. rows have different lengths, meaning not have values columns. however, empty cells @ end of row:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
how can find longest row? in example above row number 3.
if missing values nas , values @ end.
indx <- which.max(rowsums(!is.na(df1)))
or can use apply
loop on rows
indx <- which.max(apply(df1, 1, function(x) length(x[!is.na(x)])))
if missing values ''
indx <- which.max(apply(df1, 1, function(x) length(x[x!=''])))
Comments
Post a Comment