[R] Inspecting a dataframe inside a dataframe

From: Bonfigli Sandro <bonfigli_at_inmi.it>
Date: Fri 14 Jul 2006 - 00:59:15 EST


I have a rather peculiar dataframe and I have problems at inspecting it (I'm working with R 2.3.0 on Win XP).

Let say that example is a dataframe with two variables: "first" and "second"; now while "first" is a quite common numeric variable, second is a variable which contains a dataframe (this of course means that each element of "second" IS a dataframe). All the dataframes contained in "second" have the same structure, this means that they have the same number of variables with the same names and formats.
The problem for me is that some of the dataframes in "second" are zero-row and this fact blocks a procedure that I apply on "example".

I'd like to replace the zero-row dataframes in "second" with some other thing (perhaps a 0 or a NULL, I still have to determine what would be fine for my subsequent procedure).

I didn't manage to find a logical condition to identify the rows in wich "second" contains zero-row dataframes. In fact suppose that the third row of example contains a 'guilty dataframe' in "the second" variable; then if I do
> class(example$second[3])

list
> class(example[2,3])

list
> class(example[2,3][[1]])

data.frame
> class(example[[2,3]])

data.frame
> nrow(example[[2,3]])

0

this means that if I create
> example2 <- example[nrow(example$second)==0]
I don't have the desired value because in this way I pose the logical condition on example$second[i] {for i 1:nrow(example)} and I understood that example$second[i] is a list wich contains a dataframe. I tried to remove the list in various ways without success; for example I explored the function unlist but
> class(unlist(example$second[3]))

"numeric"
and this means that
> nrow(unlist(example$second[3]))

doesn't return 0

I'd be grateful for any suggestion

TIA   Sandro Bonfigli



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jul 14 02:11:08 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 14 Jul 2006 - 04:14:28 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.