Re: [R] Data frame index?

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Wed 18 Jan 2006 - 19:50:13 EST

Hi

eg. your data frame has 35 rows and 6 columns

a<-sample(1:6, 35, replace=T)
b<-1:35
vec<-rep(0,35*6)
vec[a+6*(b-1)]<-1

This shall do the replacement
your.d.f[matrix(vec,35,6, byrow=T)==1] <- 0

But I am not sure if it is quicker than a loop.

HTH
Petr

On 18 Jan 2006 at 2:35, Kenneth Cabrera wrote:

Date sent:      	Wed, 18 Jan 2006 02:35:35 -0500
From:           	Kenneth Cabrera <krcabrer@epm.net.co>
To:             	r-help@stat.math.ethz.ch
Subject:        	[R] Data frame index?

> Hi, R users:
>
> I have a data.frame (not a matrix), I got a vector with the same
> length as the number of records (rows) of the data frame, and each
> element of that vector is the column number (in a specific range of
> columns) of the corresponding record that I must set to zero.
>
> How can I do this without a "for" loop?
>
> Thank you for your help.
>
> Kenneth
>
>

Petr Pikal
petr.pikal@precheza.cz



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 Wed Jan 18 20:05:14 2006

This archive was generated by hypermail 2.1.8 : Wed 18 Jan 2006 - 22:08:08 EST