0

I have a CSV dataframe that looks like this:

SNPID,chr,position,coded_all,noncoded_all,beta,SE,pval
rs10,7,92221824,a,c,0.0176,0.0182,0.3333
rs1000000,12,125456933,a,g,0.0195,0.0076,0.009999
rs10000010,4,21227772,t,c,0.0077,0.0062,0.215
rs10000012,4,1347325,c,g,0.0098,0.0093,0.2901

The values in the pval column range from 0-1, and many are in scientific notation. When I imported this into R using readr with pval as numeric, the values in the pval that were in scientific did not appeared only as numbers. For example 9.996e-003 appears only as 9.996.

To get around this, I have imported the dataframe with p-val as character and I coerced it to numeric using as.numeric. This still caused the same problem. Is there any other way around this?

d.b
  • 32,245
  • 6
  • 36
  • 77
dam4l10
  • 349
  • 4
  • 11
  • I am not able to replicate your problem. For example, `dat <- read.table(text="rs10000012,4,1347325,c,g,0.0098,0.0093,2.901e-003", sep=",")` works fine for the final variable. – lmo Aug 29 '17 at 19:38
  • I could not replicate with `readr` either: `read_csv("SNPID,chr,position,coded_all,noncoded_all,beta,SE,pval\nrs10000012,4,1347325,c,g,0.0098,0.0093,2.901e-003")`. Please provide a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Aug 29 '17 at 19:43
  • The file is huge... so I read it in initially with: crp_num <- read_csv("~/Sync/PRSice_v1-2.25/2017-2-14 15.42.3-CRP.METAL.19.06.2009.AllSNPs.csv", col_types = cols(ClosestRefGene = col_skip(), Direction = col_skip(), SE = col_number(), beta = col_number(), pval = col_number())) – dam4l10 Aug 30 '17 at 14:04

1 Answers1

1
df <- data.frame(pval = c("1e6", "9.996e-003"))

df$pval2 <- sapply(strsplit(as.character(df$pval), 'e'), 
               function(x) as.numeric(x[1]) * 10^as.numeric(x[2]) )
Ryan
  • 934
  • 8
  • 14