0

I have a function that accepts vectors as inputs.

I have an ffdf named X, and would like to use columns of data as vectors for the function inputs.

To take a column of data named "Mag" as a vector I would use the following:

X[['Mag']]

However this is an ff vector I believe and the function will only accept a normal vector, how do I change this back to a normal vector?

I think I need to use just the physical components but I am not sure how to code this.

Thanks in advance.

jbaums
  • 27,115
  • 5
  • 79
  • 119
user3565975
  • 75
  • 2
  • 9
  • Does `X[, 'Mag']` not work? – jbaums Jun 05 '14 at 15:37
  • And did you try wrapping it in "as.vector"? – talat Jun 05 '14 at 15:40
  • Quick look at `help('ff')` suggests the data are treated by `R` just like any other data. What function are you feeding your `X[['Mag']]` to and what error message do you get? What class is that data? – Carl Witthoft Jun 05 '14 at 15:40
  • i tend to use as.ram(X$Mag) –  Jun 05 '14 at 16:08
  • I have used as.ram(X$Mag), this worked fine, however I then wanted to transfer the output 'vector' back into my ffdf, however when using the as.ffdf function, i get the following error:Error in ff(initdata = initdata, length = length, levels = levels, ordered = ordered, : bad argument initdata for existing file; initializing existing file is invalid. Interestingly using as.data.frame works fine so it does not make much sense, any ideas? – user3565975 Jun 06 '14 at 06:39
  • It's not clear on what you are doing but you can not add a vector to and ffdf, you can add an ff vector to an ffdf. So X$mynewcolumn <- as.ff(myfunctionwhichIexecute(as.ram(X$Mag))) will work. –  Jun 06 '14 at 08:04

1 Answers1

2

You can just add [] at the end.

X <- as.ffdf(data.frame(Mag = 1:10))
class(X[["Mag"]])      # ff_vector" "ff" 
class(X[["Mag"]][])    # "integer"

# X[, 'Mag'] also works as jbaums suggested
class(X[, 'Mag'])

# as.vector doesn't work
class(as.vector(X[["Mag"]])) # ff_vector" "ff" 
dixhom
  • 2,419
  • 4
  • 20
  • 36