Home > Net >  How is this the wrong number of arguments?
How is this the wrong number of arguments?

Time:11-12

I am in the process of creating a radar chart in R but keep getting this error. I'm looking through resource online and very confused as to how I have the wrong number of arguments.

My Code:

library(fmsb)

# Data
soccer_stats <- data.frame(
  row.names = c("Successful Dribbles", "Attempted Dribbles", "Successful %",
                "# of Players Dribbled Past"),
  Galvan = c(22, 32, 68.8, 22),
  LeagueAverage = c(11.5, 19.9, 60.4, 12.4)
)

soccer_stats

# Define the variable ranges: maximum and minimum
max_min <- data.frame(
  SuccessfulDribbles = c(25, 10), AttemptedDribbles = c(35, 15), 
  SuccessfulPercentage = c(70, 55), NumOfPlayersDribbled = c(25, 10)
)

rownames(max_min) <- c("Max", "Min")

# Bind the variable ranges to the data
df <- rbind(max_min, soccer_stats)
df

It gives me the following error when I run it:

df <- rbind(max_min, soccer_stats) Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match

What other arguments am I supposed to be entering?

CodePudding user response:

The error message is actually saying that the columns of the arguments do not match. In rbind, you are gluing together the matrices, one on top of the other. This means that they both need to have the same number of columns. As you have it, max_min has 4 columns while soccer_stats has 2 columns. Perhaps you are looking for cbind instead. If so, just remove the rownames of max_min to avoid a warning message.

cbind(max_min, soccer_stats)

Here is a relevant quote from the rind/cbind help file:

If there are several matrix arguments, they must all have the same number of columns (or rows) and this will be the number of columns (or rows) of the result.

CodePudding user response:

rbind needs both data frames having the same number of variables, and with the same names. Yours do not satisfy any of these conditions

  •  Tags:  
  • r
  • Related