[R] I need to change from character to numeric?

kayj kjaja27 at yahoo.com
Thu Aug 28 02:55:34 CEST 2008


Hi,

I am reading numeric data as below but the problem is the object ndata1 and
nd1 have characters instead of numeric values. I want to keep it as numeric.
Why the type has changed from numeric to character and how to avoid this
problem?



rdata1<- read.table(file="data1.txt", header=F,stringsAsFactors=F)
>rdata1
  V1
1 d1
2 11
3 20
4 13
rdata2
  V1
1 d2
2  1
3  7
4  5
5  6
>ndata1<-rdata1[2:nrow(rdata1),]
> ndata1
[1] "11" "20" "13"
>nd1<-cbind(ndata1,v2=0)
> nd1
     ndata1 v2 
[1,] "11"   "0"
[2,] "20"   "0"
[3,] "13"   "0"

-- 
View this message in context: http://www.nabble.com/I-need-to-change-from-character-to-numeric--tp19192541p19192541.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list