Hi all, I have a total newbie question, but I could really use some help. I need to read in this file: SampleID Disease E-CBIL-28-raw-cel-1435145228.cel 1 E-CBIL-28-raw-cel-1435145451.cel 2 E-CBIL-28-raw-cel-1435145479.cel 2 E-CBIL-28-raw-cel-1435145132.cel 3 E-CBIL-28-raw-cel-1435145417.cel 3 E-CBIL-28-raw-cel-1435145301.cel 2 E-CBIL-28-raw-cel-1435145558.cel 1 E-CBIL-28-raw-cel-1435145073.cel 3 E-CBIL-28-raw-cel-1435145196.cel 2 E-CBIL-28-raw-cel-1435145511.cel 1 E-CBIL-28-raw-cel-1435145336.cel 3 E-CBIL-28-raw-cel-1435145260.cel 2 E-CBIL-28-raw-cel-1435145167.cel 2 E-CBIL-28-raw-cel-1435145387.cel 3 E-CBIL-28-raw-cel-1435145099.cel 3 (I'm not sure why the disease column isn't showing up as a tab here, but it is sep by "\t" in my file. I've tried several variations on these: pd <- read.AnnotatedDataFrame ("new_treat.txt" , header = TRUE , sep="\t", row.names = "SampleID", colClasses = c(Disease = "character")) And I keep on getting this error: Error in read.table(filename, sep = sep, header = header, quote = quote, : more columns than column names Any help would be very very very appreciated! Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Reading-in-a-tab-delimitated-file-tp3013620p3013620.html Sent from the R help mailing list archive at Nabble.com.
2010/10/26 amindlessbrain <jillianrowe91286@gmail.com>> > (I'm not sure why the disease column isn't showing up as a tab here, but it > is sep by "\t" in my file. >You've got a double tab space, I don't know is there a prettier way, but paste this: pd<-read.delim("new_treat.txt",sep=" ") -- Mi³ego dnia [[alternative HTML version deleted]]
Try this: Lines <- "SampleID Disease E-CBIL-28-raw-cel-1435145228.cel 1 E-CBIL-28-raw-cel-1435145451.cel 2 E-CBIL-28-raw-cel-1435145479.cel 2 E-CBIL-28-raw-cel-1435145132.cel 3 E-CBIL-28-raw-cel-1435145417.cel 3 E-CBIL-28-raw-cel-1435145301.cel 2 E-CBIL-28-raw-cel-1435145558.cel 1 E-CBIL-28-raw-cel-1435145073.cel 3 E-CBIL-28-raw-cel-1435145196.cel 2 E-CBIL-28-raw-cel-1435145511.cel 1 E-CBIL-28-raw-cel-1435145336.cel 3 E-CBIL-28-raw-cel-1435145260.cel 2 E-CBIL-28-raw-cel-1435145167.cel 2 E-CBIL-28-raw-cel-1435145387.cel 3 E-CBIL-28-raw-cel-1435145099.cel 3" DF <- read.table(textConnection(Lines), header = TRUE) On Tue, Oct 26, 2010 at 10:35 AM, amindlessbrain <jillianrowe91286@gmail.com> wrote:> > Hi all, > > I have a total newbie question, but I could really use some help. > > I need to read in this file: > > SampleID Disease > E-CBIL-28-raw-cel-1435145228.cel 1 > E-CBIL-28-raw-cel-1435145451.cel 2 > E-CBIL-28-raw-cel-1435145479.cel 2 > E-CBIL-28-raw-cel-1435145132.cel 3 > E-CBIL-28-raw-cel-1435145417.cel 3 > E-CBIL-28-raw-cel-1435145301.cel 2 > E-CBIL-28-raw-cel-1435145558.cel 1 > E-CBIL-28-raw-cel-1435145073.cel 3 > E-CBIL-28-raw-cel-1435145196.cel 2 > E-CBIL-28-raw-cel-1435145511.cel 1 > E-CBIL-28-raw-cel-1435145336.cel 3 > E-CBIL-28-raw-cel-1435145260.cel 2 > E-CBIL-28-raw-cel-1435145167.cel 2 > E-CBIL-28-raw-cel-1435145387.cel 3 > E-CBIL-28-raw-cel-1435145099.cel 3 > > (I'm not sure why the disease column isn't showing up as a tab here, but it > is sep by "\t" in my file. > > I've tried several variations on these: > > pd <- read.AnnotatedDataFrame ("new_treat.txt" , header = TRUE , sep="\t", > row.names = "SampleID", colClasses = c(Disease = "character")) > > And I keep on getting this error: > > Error in read.table(filename, sep = sep, header = header, quote = quote, : > more columns than column names > > Any help would be very very very appreciated! > > Thanks! > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Reading-in-a-tab-delimitated-file-tp3013620p3013620.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > 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. >-- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[alternative HTML version deleted]]
if your data for the rest of the file looks like this then read.fwf will work. depending which vars you want to pull) widths= c(18,32,41) E-CBIL-28-raw-cel-1435145228.cel 1 would pull 3 vars, E-CBIL-28-raw-cel-; 1435145228.cel;1 widths <-c(32,41) E-CBIL-28-raw-cel-1435145228.cel;1 you can set it differently, assign colnames and column classes as well But the feilds must be fixed width. On Tue, Oct 26, 2010 at 5:35 AM, amindlessbrain <jillianrowe91286@gmail.com>wrote:> > Hi all, > > I have a total newbie question, but I could really use some help. > > I need to read in this file: > > SampleID Disease > E-CBIL-28-raw-cel-1435145228.cel 1 > E-CBIL-28-raw-cel-1435145451.cel 2 > E-CBIL-28-raw-cel-1435145479.cel 2 > E-CBIL-28-raw-cel-1435145132.cel 3 > E-CBIL-28-raw-cel-1435145417.cel 3 > E-CBIL-28-raw-cel-1435145301.cel 2 > E-CBIL-28-raw-cel-1435145558.cel 1 > E-CBIL-28-raw-cel-1435145073.cel 3 > E-CBIL-28-raw-cel-1435145196.cel 2 > E-CBIL-28-raw-cel-1435145511.cel 1 > E-CBIL-28-raw-cel-1435145336.cel 3 > E-CBIL-28-raw-cel-1435145260.cel 2 > E-CBIL-28-raw-cel-1435145167.cel 2 > E-CBIL-28-raw-cel-1435145387.cel 3 > E-CBIL-28-raw-cel-1435145099.cel 3 > > (I'm not sure why the disease column isn't showing up as a tab here, but it > is sep by "\t" in my file. > > I've tried several variations on these: > > pd <- read.AnnotatedDataFrame ("new_treat.txt" , header = TRUE , sep="\t", > row.names = "SampleID", colClasses = c(Disease = "character")) > > And I keep on getting this error: > > Error in read.table(filename, sep = sep, header = header, quote = quote, : > more columns than column names > > Any help would be very very very appreciated! > > Thanks! > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Reading-in-a-tab-delimitated-file-tp3013620p3013620.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > 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]]