What does the error arguments imply differing number of rows: x, y mean?
Your data.frame mat
is rectangular (n_rows!= n_cols).
Therefore, you cannot make a data.frame
out of the column- and rownames, because each column in a data.frame must be the same length.
Maybe this suffices your needs:
require(reshape2)
mat$id <- rownames(mat)
melt(mat)
Error in data.frame() arguments imply differing number of rows: 1, 0
All,
A lot of you have been getting this error with #3/ ggradar:
Error in data.frame(group = i, x = pathData[,j] * sin(angles[j-1]), : arguments imply differing number of rows: 1, 0
If you are getting this, it's likely because your dataframe isn't coverting to a tibble correctly.
To resolve it, try to read in the files with the command read_csv() instead of read.csv
read_csv reads it in as a tibble, which prevents conversion issues later. read.csv reads it in as a dataframe.
Of note, you need to call library(readr) before using read_csv
map2 error arguments imply differing number of rows
The issue is coming from the
augment(model, newdata = assessment(splits))
because in the previous step
model <- glm(egalit_scale ~ cut(income06, cc),
data = analysis(splits))
we do the analysis
on the 'splits' instead of the assessment
and this results in getting different number of rows, e.g.
out <- tidyr::expand(training_df, id, cc = 2:15) %>%
left_join(training_df)
tmp <- out$splits[[1]]
analysis(tmp)
# A tibble: 1,332 x 2
# egalit_scale income06
# <dbl> <dbl>
# 1 27.3 9.69
# 2 7.71 8.48
# 3 34.3 21.3
# 4 7.85 15.8
# 5 13.3 24.6
# 6 26.2 8.67
# 7 34.3 4.78
# 8 17.9 16.8
# 9 1.45 21.2
#10 9.84 15.7
# … with 1,322 more rows
assessment(tmp)
# A tibble: 149 x 2
# egalit_scale income06
# <dbl> <dbl>
# 1 28.6 14.8
# 2 17.8 2.47
# 3 5.03 24.3
# 4 31.5 5.79
# 5 18.4 18.0
# 6 4.05 8.06
# 7 2.28 8.16
# 8 28.6 16.8
# 9 21.1 7.03
#10 3.67 14.2
# … with 139 more rows
So, if we change the model statement with assessment
mse_df <- function(splits, cc){
model <- glm(egalit_scale ~ cut(income06, cc),
data = assessment(splits))
model_mse <- augment(model, newdata = assessment(splits)) %>%
mse(truth = egalit_scale, estimate = round(.fitted))
model_mse$.estimate
}
library(yardstick)
out1 <- tidyr::expand(training_df, id, cc = 2:15) %>%
left_join(training_df) %>%
mutate(mse = map2_dbl(splits, cc, mse_df))
out1
# A tibble: 140 x 4
# id cc splits mse
# <chr> <int> <named list> <dbl>
# 1 Fold01 2 <split [1.3K/149]> 94.9
# 2 Fold01 3 <split [1.3K/149]> 94.6
# 3 Fold01 4 <split [1.3K/149]> 93.8
# 4 Fold01 5 <split [1.3K/149]> 94.5
# 5 Fold01 6 <split [1.3K/149]> 94.0
# 6 Fold01 7 <split [1.3K/149]> 92.0
# 7 Fold01 8 <split [1.3K/149]> 88.9
# 8 Fold01 9 <split [1.3K/149]> 91.2
# 9 Fold01 10 <split [1.3K/149]> 92.8
#10 Fold01 11 <split [1.3K/149]> 86.0
# … with 130 more rows
Related Topics
Use an Image as Area Fill in an R Plot
Dual Y Axis in Ggplot2 for Multiple Panel Figure
Add Axis Tick-Marks on Top and to the Right to a Ggplot
Identifying the Outliers in a Data Set in R
Dplyr Rowwise Sum and Other Functions Like Max
How to Calculate Any Negative Number to the Power of Some Fraction in R
Show Element Values in Barplot
Count Number of Non-Na Values by Group
Nested If Else Statements Over a Number of Columns
How to Use a Graphic Imported with Grimport as Axis Tick Labels in Ggplot2 (Using Grid Functions)
Format Text Inside R Code Chunk
Create Url Hyperlink in R Shiny
Replacing Values in a Column with Another Column R
Get Margin Line Locations in Log Space
Extend an Irregular Sequence and Add Zeros to Missing Values