문제

I am trying to transform a dataframe Neigh = NULL if it has just one line:

I have tried:

Neigh <- Neigh[-(which(sapply(Neigh,nrow == 1)))]

I have one loop to plot graphs, but I don´t want to plot those with just one line. That's why I am trying to make the dataframes with one line = NULL.

도움이 되었습니까?

해결책

As Roland just said, you can use an if condition. Use it with the nrow function (which returns the number of rows of your data.frame object) and you are done.

A simple example:

df <- data.frame(1,letters[1])
if(nrow(df)==1) {
  df <- NULL
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top