[R] zero fill empty cell in data.frame

Jim Lemon jim at bitwrit.com.au
Tue Apr 19 12:02:31 CEST 2011


On 04/19/2011 07:39 PM, Simone Gabbriellini wrote:
> Hello List,
>
> I have a data frame like:
>
> 	V130	V131	V132	V133	V134	V135	V136
> 1	0		0 		0.9		0		0.9		0		0
> 2	0		0		0              		0		0		0.8
> 3	0		0		0              0		0.9		0		0
> 4	0.9		0		0              0		0		0		0.9
> 5	0		0		                0						
> 6	0		0		0		0.9		0		0		0.9
> 7	0		0 		0.8		0              0		0		0
> 8	0.9		0		                0		0.9		0.8		0
> 9	0		0		0		0.9		0.9		0		0
> 10	0		0		0		0		0		0		0.9
>
> I would like to fill the empty cells with a 0... how to address those empty cells?
>
Hi Simone,
I'm somewhat surprised that the empty cells aren't displayed as "NA". If 
they are in fact NAs, you could use:

mydataframe[is.na(mydataframe)]<-0

Jim



More information about the R-help mailing list