Ana Marija
2020-Jun-01 20:37 UTC
[R] how to load data frame where numeric will be numeric instead of character
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 Thanks Ana [[alternative HTML version deleted]]
Bert Gunter
2020-Jun-01 20:46 UTC
[R] how to load data frame where numeric will be numeric instead of character
I count 8 fields in your data and 9 names in your heading ?? Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Jun 1, 2020 at 1:38 PM Ana Marija <sokovic.anamarija at gmail.com> 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 > > Thanks > Ana > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >[[alternative HTML version deleted]]
Ana Marija
2020-Jun-01 20:50 UTC
[R] how to load data frame where numeric will be numeric instead of character
7th fileld, Direction contains only "+" and "-" On Mon, Jun 1, 2020 at 3:46 PM Bert Gunter <bgunter.4567 at gmail.com> wrote:> I count 8 fields in your data and 9 names in your heading ?? > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along and > sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > > On Mon, Jun 1, 2020 at 1:38 PM Ana Marija <sokovic.anamarija at gmail.com> > 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 >> >> Thanks >> Ana >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at 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. >> >[[alternative HTML version deleted]]
David Winsemius
2020-Jun-01 21:13 UTC
[R] how to load data frame where numeric will be numeric instead of character
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, NI 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 at 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.
Ana Marija
2020-Jun-01 21:17 UTC
[R] how to load data frame where numeric will be numeric instead of character
HI David, this is the problem:> NEP <- read.table("gokind.nephropathy.fin",header=T,stringsAsFactors=FALSE)> sapply(NEP,class)Chr BP Marker MAF A1 A2 "character" "character" "character" "character" "character" "character" Direction pValue N So even entries like Chr, BP, MAF....are characters while they should be numeric> head(NEP)Chr BP Marker MAF A1 A2 Direction pValue N 1 10 100000625 10:100000625:A:G 0.4156 G A + 0.484813 1641 2 10 100000645 10:100000645:A:C 0.216027 C A + 0.73597 1641 Can you please tell me what colClasses=colClassvec suppose to do? Thanks Ana On Mon, Jun 1, 2020 at 4:13 PM David Winsemius <dwinsemius at comcast.net> wrote:> > 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 at 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. >[[alternative HTML version deleted]]