R - removing column names from matrix
4
1
Entering edit mode
8.9 years ago
zizigolu ★ 4.3k

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 • 16k views
ADD COMMENT
6
Entering edit mode
8.9 years ago

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

ADD COMMENT
5
Entering edit mode
8.8 years ago
zizigolu ★ 4.3k
write.table(m,file="outfile,txt",sep="\t", col.names = F, row.names = F)
ADD COMMENT
4
Entering edit mode
8.9 years ago
Benn 8.3k

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 COMMENT
1
Entering edit mode

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

ADD REPLY
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 REPLY
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 REPLY
3
Entering edit mode

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

ADD REPLY
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 REPLY
1
Entering edit mode

I am in windows

ADD REPLY
2
Entering edit mode

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

ADD REPLY
1
Entering edit mode

thank you Antonio

ADD REPLY
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 REPLY
1
Entering edit mode

thank you for your suggestion

ADD REPLY
2
Entering edit mode
8.9 years ago

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

ADD COMMENT

Login before adding your answer.

Traffic: 2667 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6