[R] Creating a zero matrix when a condition doesn´t get it
Sarah Goslee
sarah.goslee at gmail.com
Tue Jul 12 12:13:38 CEST 2011
Hi,
You don't provide us with a reproducible example, so I can't provide you with
actual code. But two approaches come to mind:
1. Create da2 with one row and n columns, then change the appropriate elements,
if any, based on your conditions.
2. Do the conditional parts, then check to see whether da2 is empty.
If it is, then
replace the empty data frame with a data frame of one row and n columns.
Sarah
On Tue, Jul 12, 2011 at 3:51 AM, Trying To learn again
<tryingtolearnagain at gmail.com> wrote:
> Hi all,
>
> I first create a matrix/data frame called "d2" if another matrix
> accomplishes some restrictions "dacc2"
>
> da2<-da1[colSums(dacc2)>9,]
> da2<-da2[(da2[,13]=24),]
> write.csv(da2, file =paste('hggi', i,'.csv',sep = ''))
>
> The thing is if finally da2 cannot get/passs the filters, it cannot writte a
> csv because there is no any true condition.
>
> How can I create anyway a csv with zeros of one row and "n" columns (being n
> the number of columns of da2?
>
> I need a loop?
Rarely.
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list