[R] Changing names into number
    arun 
    smartpink111 at yahoo.com
       
    Fri Dec 27 16:46:14 CET 2013
    
    
  
Hi,
Not able to reproduce the problem when "A" is a matrix
A <- as.matrix( read.table(text="nazwa1 nazwa3  0,2531
nazwa7 nazwa5  0,562
nazwa2 nazwa6  0,65959",header=FALSE,sep=""))
 cbind(A[,1],A[,3])
#     [,1]     [,2]     
#[1,] "nazwa1" "0,2531" 
#[2,] "nazwa7" "0,562"  
#[3,] "nazwa2" "0,65959"
#data.frame
A2 <- read.table(text="nazwa1 nazwa3  0,2531
nazwa7 nazwa5  0,562
nazwa2 nazwa6  0,65959",header=FALSE,sep="",dec=",")
cbind(A2[,1],A2[,3])
#     [,1]    [,2]
#[1,]    1 0.25310
#[2,]    3 0.56200
#[3,]    2 0.65959
cbind(as.character(A2[,1]),A2[,3])
#     [,1]     [,2]     
#[1,] "nazwa1" "0.2531" 
#[2,] "nazwa7" "0.562"  
#[3,] "nazwa2" "0.
 A2[,c(1,3)]
      V1      V3
1 nazwa1 0.25310
2 nazwa7 0.56200
3 nazwa2 0.65959
#If you have a character and numeric column, it is better to store in data.frame.
A.K.
Hi, i have one problem in. I have a matrix A: 
nazwa1 nazwa3  0,2531 
nazwa7 nazwa5  0,562 
nazwa2 nazwa6  0,65959 
When i use function cbind(A[,1], A[,3]) R gaves me matrix like this: 
1   0,2531 
3   0,562 
2   0,65959 
But i want matrix: 
nazwa1  0,2531 
nazwa7   0,562 
nazwa2   0,6595 
I dont want to R changing names into number. How I can do this?
    
    
More information about the R-help
mailing list