Error: Problem with `mutate()` input `Value`. x requires numeric/complex matrix/vector arguments?

Error: Problem with `mutate()` input `Value`. x requires numeric/complex matrix/vector arguments?

当我尝试将一个名为 value 的列乘以 1000 时出现错误。我使用 tidyverse 执行此操作,因为我更喜欢这种方式。

这是我的数据类型:

test_data <- structure(list(Index = c("71", "71", "71", "71", "71", "71", 
"71", "71", "71", "71", "71", "71", "71", "71", "71", "71", "71", 
"71", "71", "71", "71"), Variant = c("Estimates", "Estimates", 
"Estimates", "Estimates", "Estimates", "Estimates", "Estimates", 
"Estimates", "Estimates", "Estimates", "Estimates", "Estimates", 
"Estimates", "Estimates", "Estimates", "Estimates", "Estimates", 
"Estimates", "Estimates", "Estimates", "Estimates"), `Region, subregion, country or area *` = c("WORLD", 
"WORLD", "WORLD", "WORLD", "WORLD", "WORLD", "WORLD", "WORLD", 
"WORLD", "WORLD", "WORLD", "WORLD", "WORLD", "WORLD", "WORLD", 
"WORLD", "WORLD", "WORLD", "WORLD", "WORLD", "WORLD"), Notes = c(NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_, 
NA_character_, NA_character_, NA_character_, NA_character_, NA_character_
), `Country code` = c("900", "900", "900", "900", "900", "900", 
"900", "900", "900", "900", "900", "900", "900", "900", "900", 
"900", "900", "900", "900", "900", "900"), Type = c("World", 
"World", "World", "World", "World", "World", "World", "World", 
"World", "World", "World", "World", "World", "World", "World", 
"World", "World", "World", "World", "World", "World"), `Parent code` = c("0", 
"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", 
"0", "0", "0", "0", "0", "0", "0"), year = c("2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020", "2020", "2020", "2020", "2020", "2020", 
"2020", "2020", "2020"), age_band = c("0-4", "5-9", "10-14", 
"15-19", "20-24", "25-29", "30-34", "35-39", "40-44", "45-49", 
"50-54", "55-59", "60-64", "65-69", "70-74", "75-79", "80-84", 
"85-89", "90-94", "95-99", "100_plus"), value = c("677 942", 
"664 439", "641 267", "612 196", "597 388", "594 692", "605 531", 
"544 819", "493 789", "479 366", "445 773", "387 849", "322 142", 
"269 644", "188 677", "123 782", "81 930", "42 186", "16 680", 
"4 134", "573")), row.names = c(NA, -21L), class = c("tbl_df", 
"tbl", "data.frame"))

代码如下:

numbers_multipl <- test_data %>%
  dplyr::mutate(Value = 'value' %*% 1000)

这是我得到的错误:

Error: Problem with mutate() input Value. x requires numeric/complex matrix/vector arguments ℹ Input Value is "value" %*% 1000.

不确定为什么会出现此错误。这有点奇怪,但可能是因为我正在使用 mutate?我尝试了摘要,但没有用。

名为 value 的列的数据类型是字符。尝试将其更改为数字或双精度,然后您可以使用 mutate 或 summarise 将其相乘。 示例:

numbers_multipl <- test_data %>%
  mutate(new_value= as.numeric(str_replace(value, " ", "")),
         value_times_1000 = new_value*1000
)