Skip to content

diff doesnot work

2 messages · george brida, William Dunlap

#
Dear R users,

I have a txt file entitled coc composed by one column of numeric values
without header and having 50 rows. This file is under the following path:

C:\\Users\\intel\\Documents\\TR

I have written the following lines:

xcx=read.table("C:\\Users\\intel\\Documents\\TR\\coc.txt",header=F)
xc=log(xcx)

I have obtained the series xc but when I wrote
x=diff(xc)

I obtained the following message:

data frame with 0 columns and 50 rows

I don't know where is the problem. Can you help me please
#
diff() does not work on data.frames so you need to give it a column
from the data.frame, as a vector.
  diff(data.frame(P=c(1,2,3,5,7,11,13,17))$P)
  [1] 1 1 2 2 4 2 4

You get different errors for multi- and single-column data.frames
  > diff(data.frame(P=c(1,2,3,5,7,11,13,17), F=c(1,1,2,3,5,8,13,21)))
  Error in r[i1] - r[-length(r):-(length(r) - lag + 1L)] :
    non-numeric argument to binary operator
  > diff(data.frame(P=c(1,2,3,5,7,11,13,17)))
  data frame with 0 columns and 8 rows
Bill Dunlap
TIBCO Software
wdunlap tibco.com
On Mon, Feb 6, 2017 at 2:21 PM, george brida <george.brida at gmail.com> wrote: