0

my number in output look like this:

[1] 4.032134 1.000000 2.000000
[1] 3.476687 1.000000 3.000000
[1] 2.710619 1.000000 4.000000

first I want to round numbers in second and third column(without zeros): 1,2,3 and second I want to have header for each column. generally I want to have suche an output:

  Distance  First  second
[1] 4.032134  1      2
[1] 3.476687  1      3
[1] 2.710619  1      4

does it possible to do it in R? How can I do that?

UPDATE

I am generating this output so:

while(i < end-start+1)
{ 
  n<-1
  m<-strsplit(datalist[i],split=",")
  m<-sapply(m,as.numeric)
  m<-c(m)
  while(i+n<=end-start+1)
  {
    k<-strsplit(datalist[i+n],split=",")
    k<-sapply(k,as.numeric)
    k<-c(k)
    alignment<-dtw(k,m)
    output<-c(alignment$distance,round(i,digits=1),i+n)
    print(output)

    n<-n+1
  }

  i<-i+1
}
Kaja
  • 2,962
  • 18
  • 63
  • 99
  • 1
    It is certainly possible. Please see http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for ways to improve your question, which is so basic that should be found in any R textbook. Anyway start by giving the type of your variable. Is is a data frame ? – Karl Forner Jan 09 '14 at 09:15

1 Answers1

2

This example works for your small dataset. It is probably not the most elegant but it works.

Make a vector of your data

DataSet<-c(4.032134,1.000000,2.000000,3.476687,1.000000,3.000000,2.710619,1.000000,4.000000)

Transform to a matrix with 3 columns and three rows, sorted by rows
DataMatrix<-matrix(DataSet, byrow=T, ncol=3)

The names of your columns according to question
Names <- c("Distance", "First", "second")

Here is the crux, use the command colnames(x), and you are done
colnames(DataMatrix) <- Names

Printout on screen
DataMatrix

KnutE
  • 36
  • 1