Dinesh
Dinesh

Reputation: 663

Dropping extra column in Tab delim file

I tried to merge different tab delim files into single file using the following R command.

If you observe, I even save the file using write.table command. Now i need to read the same files for further analysis. The biggest problem I am facing is that there is an extra column without any column name created automatically.Screen shot of delim file opened in excel with Extra column(Red) If you observe that there is a column (Red colour) created automatically when I use the write.table function. I want to get rid of that column as it hampers all further calculations.My actual output like how I need it to be saved

combine=function(file) { 
split_list <- unlist(strsplit(file,split=","))
setwd("D:/combine")
dataset <- do.call("cbind",lapply(split_list,FUN=function(files) { read.table(files,header=TRUE, sep="\t") } ) )
names(dataset)[1]=paste("Probe_ID")
drop=c("ProbeID")
dataset=dataset[,!(names(dataset)%in%drop)]
dataset$X=NULL
write.table(dataset,file="D:/output/illumina.txt",sep="\t",col.names=NA)
return ("illumina.txt") 
}

Upvotes: 3

Views: 763

Answers (2)

hatmatrix
hatmatrix

Reputation: 44872

As @James says -- or use row.names=1 in read.table() to indicate that the first column designates the row identifiers of the table when reading the table back into R.

Upvotes: 2

James
James

Reputation: 66834

Use the argument row.names=FALSE in write.table.

Upvotes: 5

Related Questions