as.integer function is converting row names in to number
1
0
Entering edit mode
3.5 years ago
singhsk2622 ▴ 20

I used to this

mydata3 <- data.frame(sapply(mydata2, as.integer))

but now i see that row names which is gene names, has been converted to number like 1-200). but i should point that same command i used sometimes ago then it was working well. So i thought there are some proenter code hereblem with my file then i used old file on which this command was working but i am seeing same problem like gene name is converted in to number here is full script-

countsTable<-read.table("JW.txt",header=TRUE,stringsAsFactors=TRUE,row.names=1)
mydata2 <- countsTable/1000
mydata3 <- data.frame(sapply(mydata2, as.integer))
str(mydata3)

please let me know.

R • 639 views
ADD COMMENT
0
Entering edit mode
3.5 years ago

Explanation: your column is stored as factors

Solution1: as.integer(as.character(mycolumn))

Solution2: use stringAsFactors=F when reading the data

ADD COMMENT
0
Entering edit mode

thnaks for comment

countsTable<-read.table("EF_new.txt",header=TRUE,stringsAsFactors=FALSE,row.names=1)

i used this but name is still vanishing and when i used

mydata3 <- data.frame(sapply(mydata2, as.integer(as.character(mydata2))))

so getting this error Error in match.fun(FUN) : 'as.integer(as.character(mydata2))' is not a function, character or symbol In addition: Warning message: In match.fun(FUN) : NAs introduced by coercion

ADD REPLY
1
Entering edit mode

hi thanks!! its working now. i changed it like this.

mydata2[] <- sapply(mydata2, as.integer)
ADD REPLY

Login before adding your answer.

Traffic: 1179 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