简体   繁体   English

read.csv() 读取 data.frame OK readr::read_csv() for the same data.frame 失败,为什么?

[英]read.csv() reads the data.frame OK readr::read_csv() for the same data.frame fails, why?

below, when I read in my data.frame using readr::read_csv() , my subsequent code produces NA for yi .下面,当我使用readr::read_csv()读取我的 data.frame 时,我的后续代码为yi生成NA

But when I read in my data.frame using Base R's read.csv() , my subsequent code correctly computes yi .但是,当我使用 Base R 的read.csv()读入我的 data.frame 时,我的后续代码会正确计算yi

I wonder what's going on?我想知道发生了什么事?

library(tidyverse)

d <- read_csv("https://raw.githubusercontent.com/fpqq/w/main/n.csv")
d2 <- read.csv("https://raw.githubusercontent.com/fpqq/w/main/n.csv")


d %>% group_by(study) %>%  # change `d` to `d2` and compare the results
  mutate(n = unlist(mean(c(nT,nC))),
         N = nT+nC,
         w = (nT+nC-2)*.8,
         icc = .15,
          yi = ifelse(assign_type=="group", yi*w, yi)
  ) %>% ungroup

by default read_csv() converts empty strings to NA .默认情况下read_csv()将空字符串转换为NA

Try d <- read_csv("https://raw.githubusercontent.com/fpqq/w/main/n.csv", na = c("NA"))尝试d <- read_csv("https://raw.githubusercontent.com/fpqq/w/main/n.csv", na = c("NA"))

Both data sets should be the same now.两个数据集现在应该是相同的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM