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
}
質問
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
}