当尝试使用 as.numeric 将一列字符(数字字符串,例如“0.1234”)转换为数字时,某些值会返回NA警告“强制转换引入的 NA”。作为 s 返回的字符NA似乎与正确作为数字返回的字符没有任何不同。有谁知道可能是什么问题?
已经尝试查找任何可以隐藏在某些值中的非数字字符(如 \',\')。我确实找到了包含“-”(例如“-0.123”)的字符串确实变成了NAs,但这些只是变成了NAs的字符串的一部分。另外,尝试寻找字符串内的空格。这似乎也不是问题。
data$y\n [1] "0.833250539"  "0.820323535"  "0.462284612"  "0.792943985"  "0.860587952"  "0.729665177"  "0.461503956"  "0.625871118" \n [9] "0.740999346"  "0.962727964"  "0.971089266"  "0.869004848"  "0.828651766"  "0.900648732"  "0.970326033"  "0.898123286" \n[17] "0.911640765"  "0.902442126"  "0.843392097"  "0.763421844"  "0.892426243"  "0.380433624"  "0.925017633"  "0.725470821" \n[25] "0.699924767"  "0.689061225"  "0.907462936"  "0.888064239"  "0.913547115"  "-\xe2\x80\xac0.625103904\xe2\x80\xad" "0.897385961"  "0.889727462" \n[33] "0.90127339"   "0.947012474"  "0.948883588"  "0.845845512"  "0.97866966"   "0.796247738"  "0.864627056"  "0.266656189\xe2\x80\xad" \n[41] "0.894915463"  "0.969690678"  "0.771365656\xe2\x80\xad"  "0.88304436"   "0.954039006"  "0.836952199"  "0.731558669\xe2\x80\xad"  "0.907224294" \n[49] "0.622059127"  "0.887742343"  "0.917550343"  "0.97240334\xe2\x80\xad"   "0.902841957" …Run Code Online (Sandbox Code Playgroud) 有什么方法可以添加 knitr 不知道的包吗?我在 Overleaf 中使用 knit,并且需要使用包“pacma”、“nonlinearTseries”和“RHRV”。但是当我尝试安装它们时,它不起作用。\n我尝试使用库函数添加它们,但它给我带来了错误消息。
\nlibrary("RHRV")\nError in library("RHRV"): there is no package called \xe2\x80\x99RHRV\xe2\x80\x99\nRun Code Online (Sandbox Code Playgroud)\n\n 我需要计算包含许多组的 data.frame 的箱线图统计数据。
我理想中需要的是:
library(dplyr)
iris %>%
  group_by(Species) %>%
  summarise(boxplot=boxplot.stats(Sepal.Length))) # + some kind of magic
# A tibble: 3 x 6
  Species    lower_whisker lower_hinge median upper_hinge upper_whisker
  <fct>              <dbl>       <dbl>  <dbl>       <dbl>         <dbl>
1 setosa               4.3         4.8    5           5.2           5.8
2 versicolor           4.9         5.6    5.9         6.3           7  
3 virginica            5.6         6.2    6.5         6.9           7.9
Run Code Online (Sandbox Code Playgroud)
但到目前为止,我已经成功地完成了半purrr映射,但无法解压它。
boxplot.stats2 <- function(x, ...) {
  res <- boxplot.stats(x, ...)
  res <- res$stats
  names(res) <- c('lower_whisker','lower_hinge','median','upper_hinge','upper_whisker')
  #t(as.data.frame(res))
  res
}
iris %>%
  group_by(Species) %>% …Run Code Online (Sandbox Code Playgroud) 我有以下循环。我试图将其转换为使用apply函数而不是循环,但我不知道如何重写代码。
for (i in 1:dim(Y)[2]) {
     K = K_origin
     print(i)
     e = lmmlite::eigen_rotation(K, t(Y)[i,], use_cpp = T)
     VC = lmmlite::fitLMM(
       e$Kva,
       e$y,
       e$X,
       reml = T,
       use_cpp = T,
       tol = 1e-6,
       check_boundary = T
     )
     write.table(
       VC$sigmasq_g,
       "Vg_temp.txt",
       row.names = F,
       col.names = F,
       append = T,
       quote = F,
       sep = "\n"
     )
     write.table(
       VC$sigmasq_e,
       "Ve_temp.txt",
       row.names = F,
       col.names = F,
       append = T,
       quote = F,
       sep = "\n"
     )
}
Run Code Online (Sandbox Code Playgroud)
我想要这样的结果
Vg                  Ve …Run Code Online (Sandbox Code Playgroud)