You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure手动输入数据R模块报错:替换行数与数据行数不匹配如何解决?

Troubleshooting the R Script Error in Azure ML

Hey Ann, let's break down this issue and get your script working smoothly!

The Root Cause

R is case-sensitive when referencing column names, and that's exactly what's causing your error. Looking at your data columns, you have CITY_ID (all uppercase), but in your R code you're trying to access test2$City_ID (camel case: uppercase C, lowercase i/d).

Since there’s no column named City_ID in your data frame, as.numeric(test2$City_ID) returns an empty numeric vector (length 0). When you try to assign this empty vector back to your 1-row data frame, R throws the "replacement has 0 rows, data has 1" error because the lengths don’t align.

Fix Steps

  1. Correct the column name case in your R code. Update this line:
    test2$City_ID<- as.numeric(test2$City_ID)
    
    To match your actual column name:
    test2$CITY_ID<- as.numeric(test2$CITY_ID)
    
  2. Verify column names upfront (optional but useful) to avoid similar issues later. Add this line at the start of your script to confirm exactly what columns exist in your data frame:
    print(colnames(test2))
    
  3. Quick note on Ad_Slot_Floor_Price: Your current code uses as.numeric(as.factor(test2$Ad_Slot_Floor_Price)) – keep in mind this converts factor levels to their numeric positions, not the original numeric values. If your Ad_Slot_Floor_Price contains actual numeric data (including proper NA instead of Na), consider cleaning missing values first (with na.omit() or replace()) or using as.numeric(as.character(test2$Ad_Slot_Floor_Price)) instead (just be sure to handle NAs carefully).

After making these adjustments, your script should assign numeric values correctly without the row mismatch error.

内容的提问来源于stack exchange,提问作者Ann S.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:04:56