i have matrix read file. , sure consists of characters. matrix has 4 columns called "type","time","x value","y value". , except "type" other 3 columns values' numbers.
i want arithmetic operations subtraction on time column. gives me :
non-numeric argument binary operator error
my data is:
data <-as.matrix(read.table("data/firstdata.cal")) here content of data
type time x y 1 r 1383154550660 0.5638523 0.5157838 2 r 1383154550732 0.5637349 0.5152285 3 r 1383154550778 0.5634450 0.5154306 4 r 1383154550872 0.5631472 0.5145780 5 r 1383154550922 0.5633539 0.5150688 6 r 1383154550984 0.5630451 0.5148284 i change class data frame writing:
data<-as.data.frame(data) data[, 2] <- as.numeric(as.character( data[, 2] )) then want subtraction between rows this:
i<-1 output<-matrix(0,nrow(data),ncol(data)) while(data[i,1]!='ss') i<-i+1 temp<-0 while(i<nrow(data)){ if(data[i,1]=='ss'){ temp<-data[i,3] output[i+1,1]<-temp n<-n-1 } else { j<-i+1 while(data[j,2]-data[i,2]<=700 ) { j<-j+1 } k<-0 while (data[j,2]-data[i,2]<=2000){ output[k,3]<-data[i,3] output[k,2]<-temp output[k,1]<-data[j,2]-data[i,2] j<-j+1 k<-k+1 } } i<-i+1 } but values before changing data frame , after changing data frame different. so, should original values without getting error?
Comments
Post a Comment