Biostar Beta. Not for public use.
R - removing column names from matrix
1
Entering edit mode
12 months ago
F ♦ 3.4k
Iran

hi,

i have a correlation matrix of genes but i am going to remove alphabet from rows and columns to prepare my file for matlb i did like below

mycounts <- read.table("tmatnorm_rld500.txt", header = T, sep = "\t", row.names=1) > head(mycounts[,1:3]) AT1G01060 AT1G01170 AT1G01180 AT1G01060 1.0000000 0.3193360 0.6272994 AT1G01170 0.3193360 1.0000000 0.3178880 AT1G01180 0.6272994 0.3178880 1.0000000 AT1G01260 0.2658624 0.3588030 0.2542234 AT1G01380 0.6178751 0.1561297 0.7052692 AT1G01490 0.5990499 0.6129301 0.6424225 > rownames(mycounts) <- NULL > head(mycounts[,1:3]) AT1G01060 AT1G01170 AT1G01180 [1,] 1.0000000 0.3193360 0.6272994 [2,] 0.3193360 1.0000000 0.3178880 [3,] 0.6272994 0.3178880 1.0000000 [4,] 0.2658624 0.3588030 0.2542234 [5,] 0.6178751 0.1561297 0.7052692 [6,] 0.5990499 0.6129301 0.6424225 > colnames(mycounts) <- NULL > > head(mycounts[,1:3]) [,1] [,2] [,3] [1,] 1.0000000 0.3193360 0.6272994 [2,] 0.3193360 1.0000000 0.3178880 [3,] 0.6272994 0.3178880 1.0000000 [4,] 0.2658624 0.3588030 0.2542234 [5,] 0.6178751 0.1561297 0.7052692 [6,] 0.5990499 0.6129301 0.6424225 > write.table(mycounts, file = "correlation.txt", dec = ".", sep = "\t", quote = FALSE, row.names=F) > mycounts <- read.table("correlation.txt", header = T, sep = "\t") > head(mycounts[,1:3]) V1 V2 V3 <---this line 1 1.0000000 0.3193360 0.6272994 2 0.3193360 1.0000000 0.3178880 3 0.6272994 0.3178880 1.0000000 4 0.2658624 0.3588030 0.2542234 5 0.6178751 0.1561297 0.7052692 6 0.5990499 0.6129301 0.6424225 but as you consider, i have something in colnames?? then how I can get rid of alphabet and only have the similarity values please? thank you

R • 6.8k views
ADD COMMENTlink
6
Entering edit mode
13 months ago
National Institutes of Health, Bethesda…

Add col.names=FALSE to the write.table() command and you should have a matrix with no row or column names.

ADD COMMENTlink
5
Entering edit mode
12 months ago
F ♦ 3.4k
Iran
write.table(m,file="outfile,txt",sep="\t", col.names = F, row.names = F)
ADD COMMENTlink
4
Entering edit mode
11 months ago
Benn 6.9k
Netherlands

V1 to V3 is what R assigns to columns, when there are no header names!

Try open your text file in notepad or something similar and see if you have colnames in there?

ADD COMMENTlink
1
Entering edit mode

thank you my file was too big to be opened in notepad ++

ADD REPLYlink
2
Entering edit mode

You could use less, vi, or head -1 tmatnorm_rld500.txt to see the first line(s) of your file without having to open it.

ADD REPLYlink
1
Entering edit mode

sorry you mean I did like below

> less(mycounts)
Error: could not find function "less"
> head -1 mycounts
Error: unexpected symbol in "head -1 mycounts"
ADD REPLYlink
3
Entering edit mode

less, vi, and head are all linux/unix commands that will not run in R.

ADD REPLYlink
2
Entering edit mode

These (less, head, vi) are bash commands working only in pure linux. These commands do not work in R unless you invoke the system or system2 function in R

ADD REPLYlink
1
Entering edit mode

I am in windows

ADD REPLYlink
2
Entering edit mode

Try to use notepad++ directly (easier for you) or the col-names and row-names FALSE

ADD REPLYlink
1
Entering edit mode

thank you Antonio

ADD REPLYlink
2
Entering edit mode

I am not an ms-dos expert, but you can check your file in the command line console of windows. If you open the program Command Prompt, you'll have to go to your directory with your file and type in:

more file.txt

It will show you the first 'page' of your file, you can then stop showing it with CTRL-break.

ADD REPLYlink
1
Entering edit mode

thank you for your suggestion

ADD REPLYlink
2
Entering edit mode
12 months ago
Spain. Universidad de Córdoba

Or use the notepad++ program as I showed you to erase and edit the file

ADD COMMENTlink

Login before adding your answer.

Similar Posts
Loading Similar Posts
Powered by the version 2.1