[R] how to load data frame where numeric will be numeric instead of character

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Mon Jun 1 23:13:27 CEST 2020


On 6/1/20 1:37 PM, Ana Marija wrote:
> Hello,
>
> I have a dataframe like this:
>
>    Chr        BP           Marker      MAF A1 A2 Direction   pValue    N
> 1  10 100000625 10:100000625:A:G 0.416562  G  A         - 0.558228 1594
> 2  10 100000645 10:100000645:A:C 0.215182  C  A         - 0.880622 1594
> ...
>
> which I load with:
> NEU <- read.table("gokind.neuropathy.fin", header=T,stringsAsFactors=FALSE)
>
> and every column is numeric. How to say have all numeric ones stay numeric
> like: Chr, BP, MAF, pValue, N


I cannot figure out what the problem is. You say every column is 
numeric. It's not possible to have a column that contains the value 
"10:100000625:A:G" be numeric.


If you meant to say the every column was character, then the answer 
might be:


colClassvec <- rep("numeric",9)
colClassvec[ c(3,5:7)] <- "character"

NEU <- read.table("gokind.neuropathy.fin", header=T,stringsAsFactors=FALSE, colClasses=colClassvec)

-- 
David.

>
> Thanks
> Ana
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list