By definition, objects of class data.frame are 2D objects. If you are
using more dimensions, you are using objects of class "array". These
objects don't allow to mix different types that's why there are all
characters. To me it seems that a list might be more appropriate for your
case. You may also want to reconsider the structure of your data, and use a
data.frame with date as an additional column.
Regarding your second question, "==" goes through each element on the
left of the == and compares it successively with each element on the right
of the expression (with recycling):
> c("no", "yes", "no", "yes") == c("yes", "no")
 FALSE FALSE FALSE FALSE
> c("no", "yes", "yes", "no") == c("yes", "no")
 FALSE FALSE TRUE TRUE
You probably need to use %in% instead
> c("no", "yes", "yes", "no") %in% c("yes", "no")
 TRUE TRUE TRUE TRUE
On Sat, Jun 28, 2014 at 4:24 AM, Bhattacharya,Souvik <[log in to unmask]> wrote:
> Hello all,
> I am working on a 3 dimensional dataframe where the 3rd dimension is
> date. I used abind function to join different dataframes to give a 3
> dimensional structure. The dataframes donot have same number of rows and
> hence I have introduced "NA" to equate all dataframes to have 1000 rows
> I keep adding each dataframes to a 3dim "Clean" dataframe using the
> Clean <- abind(Clean,totalm,along=3)
> After the 3d dataframe is created, all elements seems to be of
> character type.
> My first question , is there a way to change the numeric columns to
> numeric type. For instance, there is a list of vector say vec =
> c(1:5,9:25, 55:89) which are of numeric type for each date. I want to
> change all these columns in the Clean 3 dim dataframe to numeric type.
> is there any elegant way to achieve this.
> My next question is, if I want to subset a smaller cube from this 3 dim
> dataframe,(say I want to use something like
> Clean[which(Clean[,"Color" == c("Red","Blue")]),], i.e. I want to
> extract all those rows from every date where Clean[,"Color", ] is either
> red or Blue ) is there any way to do this in R. Whenever I tried to
> subset, it gives me a one dimensional array.
> I shall be glad to receive any suggestions from the community in this
> This list strives to be beginner friendly. However, we still ask that you
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
This list strives to be beginner friendly. However, we still ask that you
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.