[R] Does R have an equivalent for Matlab's cell array?

arun smartpink111 at yahoo.com
Sat Dec 22 21:29:37 CET 2012


HI,

May be this helps:
dat1 <- read.table(text="
20100914 08:01,    3.74
20100914 08:11,    3.74
20100914 08:21,    3.71
20100914 08:31,    4.39
20100914 08:41,    3.74
20100915 08:01,    3.64
20100915 08:11,    3.54
20100915 08:21,    3.61
20100915 08:31,    4.49
20100915 08:41,    3.84
", sep=",",header=FALSE,stringsAsFactors=FALSE)
tapply(dat1$V2,list(as.Date(dat1$V1,format="%Y%m%d %H:%M")),function(x) x)
#$`2010-09-14`
#[1] 3.74 3.74 3.71 4.39 3.74
#
#$`2010-09-15`
#[1] 3.64 3.54 3.61 4.49 3.84
A.K.




----- Original Message -----
From: Matthijs Daelman <matthijs.daelman at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Saturday, December 22, 2012 5:58 AM
Subject: [R] Does R have an equivalent for Matlab's cell array?

Hi

I have a time series of measurements: every 10 min. a value was logged.

The data look like:

20100914 08:01     3.74
20100914 08:11     3.74
20100914 08:21     3.71
20100914 08:31     4.39
20100914 08:41     3.74

This data spans several months.

I would like to group the data per day. In Matlab it is fairly easy to obtain a cell array, of which the first column contains the date of each day, and the second column contains a vector, that in its turn contains all values for the corresponding day.

That looks like

14-9-2010    [3.74 3.74 3.71 4.39 3.74...]
15-9-2010    [...]
and so on.

Is it possible to create a similar data structure in in R? I was thinking of a data frame, similar to the Matlab's cell array, but it doesn't look like data frames can contain vectors. Something like a two dimensional list would do the trick, I believe, but does that exist?

Thanks

Kind regards

Matthijs Daelman

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





More information about the R-help mailing list