0
votes

I'm trying to save a number of spectral measurements in a data.frame. Each measurement has a number of attributes as well as two channels of spectral data, each with 2048 data points. I would like to have each channel be a single point of data in the data frame.

Something like this:

  timestamp           type integration channel1 channel2
1 2011-10-02 02:00:01 D    2000        (spec)   (spec)
2 2011-10-02 02:00:07 D    2000        (spec)   (spec)

Where each (spec) is a vector of 2048 values. I simply cannot get it to work, and I now turn to you guys for help.

Thanks in advance.

2
That's not what a dataframe is for.Start using lists instead (a data frame is nothing more but a special type of list anyway) - Joris Meys
@Bjørn Madsen your title is a bit confusing since you are not adding a vector as each variable but a vector as each observation/cell of a variable/column - Tyler Rinker
@JorisMeys It did feel a bit hackish. Guess it's a list of lists then. - Bjørn Madsen
@TylerRinker Edited it to something better (hopefully). - Bjørn Madsen
@BjørnMadsen Shouldn't feel hackish. Lists are made for that kind of stuff ;-). - Joris Meys

2 Answers

2
votes

You can add matrix as one of data.frame fields, so you have to put all vectors as matrix rows.

DF <- data.frame(timestamp=1:3, type=LETTERS[1:3], integration=rep(2000, 3))
DF$channel1 <- matrix(rnorm(3*2048), nrow=3)
DF$channel2 <- matrix(rnorm(3*2048), nrow=3)
ncol(DF)# == 5
1
votes

I think what you want is doable but I may not be fully understanding your question. Heed Joris's suggestion though as this may be a better way of storing your data. You can accomplish what you want by storing the vectors of 2048 values in a list that you then add to the data frame as a column. Your table wasn't easily imported (for me anyway) with read.table so I made up my own data frame and example.

DF <- data.frame(timestamp=1:3, type=LETTERS[1:3], integration=rep(2000, 3))
DF$channel1 <- list(c(rnorm(2048)), c(rnorm(2048)), c(rnorm(2048)))
DF$channel2 <- list(c(rnorm(2048)), c(rnorm(2048)), c(rnorm(2048)))