Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

But when I read in my data.frame using Base R’s read.csv(), my subsequent code correctly computes yi.

I wonder what’s going on?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

by default read_csv() converts empty strings to NA.

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

Both data sets should be the same now.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading