簡體   English   中英

錯誤 $ 運算符對原子向量無效

[英]Error $ operator is invalid for atomic vectors

我有一個具有以下結構的數據框“SF”

> str(SF)
Classes ‘data.table’ and 'data.frame':  6768 obs. of  8 variables:
 $ Class-Entity-Month        : chr  "Bagel Shop--1--1" "Bagel Shop--1--2" "Bagel Shop--1--3" "Bagel Shop--1--4" ...
 $ Customer Class            : chr  "Bagel Shop" "Bagel Shop" "Bagel Shop" "Bagel Shop" ...
 $ Entity                    : int  1 1 1 1 1 1 1 1 1 1 ...
 $ SBMONTH                   : int  1 2 3 4 5 6 7 8 9 10 ...
 $ End Market                : chr  "Food Service" "Food Service" "Food Service" "Food Service" ...
 $ Customer Class Seasonality: num  0.0567 0.0562 0.0702 0.0685 0.0736 0.0921 0.0912 0.0936 0.0975 0.0922 ...
 $ End Market Seasonality    : num  0.077 0.0792 0.0923 0.0808 0.0804 0.0873 0.0897 0.0903 0.083 0.0816 ...
 $ Seasonality               : num  0.0567 0.0562 0.0702 0.0685 0.0736 0.0921 0.0912 0.0936 0.0975 0.0922 ...

我需要根據以下規則將具有來自表“SF”的值的列添加到另一個數據框中:

df <- mutate(df, "Coef" = SF$Seasonality[match(`Class-Entity-Month`, SF$`Class-Entity-Month`)])

變異 function 非常受歡迎,並且可以在我的 100 行代碼中使用。 但在這種情況下,我收到了錯誤消息:

Error in `mutate()`:
! Problem while computing `Seasonality = ...[]`.
Caused by error in `` New_Customer_Monthly_Sales$`Class-Entity-Month` ``:
! $ operator is invalid for atomic vectors

怎么了?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM