[R] Inspecting a dataframe inside a dataframe
Bonfigli Sandro
bonfigli at inmi.it
Thu Jul 13 16:59:15 CEST 2006
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
More information about the R-help
mailing list