Re: [R-sig-eco] Recode several variables with conditions in a data frame

2012-07-03 Thread Manuel Spínola
Thank you very much Bret.

Best,

Manuel

2012/7/3 Bret Collier 

> Not very elegant or efficient, but for only a couple of columns needing
> left out something simple like this should work.
>
> xx=data.frame(x=c(2, 10), y=c(2, 0), z=c(4, 3))
> yy=xx[,2:3]
> yy[yy!=0]=1
> data.frame(x=xx[,1], yy)
>
> bret
>
>
>
>
> On 7/3/2012 9:18 PM, Manuel Spínola wrote:
>
>> Thank you Bret.
>>
>> What if I need to leave out some variables from my data frame.  I have 22
>> variables and I need to leave the 2 first variables out of the condition.
>>
>> Best,
>>
>> Manuel
>>
>> 2012/7/3 Bret Collier 
>>
>>  Manuel,
>>> Something like this should work for your example.
>>>
>>> xx=data.frame(x=c(2, 10), y=c(2, 0))
>>> xx[xx!=0]=1
>>> xx
>>>x y
>>> 1 1 1
>>> 2 1 0
>>>
>>> Bret
>>>
>>>
>>> On 7/3/2012 8:12 PM, Manuel Spínola wrote:
>>>
>>>  Dear list members,

 I want to recode a data frame but do it for several variables at the
 same
 time.  I want to give all the values > or equal than 1 a value of 1 and
 all
 the remaining values (0) keep in 0.

 data.frame: newdf

 var1 var2 var3 var4
 A   1  0 4
 B   3  2 1
 C   0  5 1

 My real data frame has several more variables.

 I am using the recode function from the epicalc package:

   recode(vars=newdf[, 2:4], old.value= newdf[, 2:4] >= 1, new.value=1)

>
>
 Error en recode.default(vars = newdf[, 2:4], old.value = newdf[, 2:4] >=
   :
 objeto '.data' no encontrado

 I guess I am not setting the condition in a proper way.

 Best,

 Manuel



 ___
 R-sig-ecology mailing list
 R-sig-ecology@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
 https://stat.ethz.ch/mailman/listinfo/r-sig-ecology>
 >


  ___
>>> R-sig-ecology mailing list
>>> R-sig-ecology@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-ecology>
>>> >
>>>
>>>
>>
>>
>>
> __**_
> R-sig-ecology mailing list
> R-sig-ecology@r-project.org
> https://stat.ethz.ch/mailman/**listinfo/r-sig-ecology
>



-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.ac.cr
mspinol...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative HTML version deleted]]

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


Re: [R-sig-eco] Recode several variables with conditions in a data frame

2012-07-03 Thread Bret Collier
Not very elegant or efficient, but for only a couple of columns needing 
left out something simple like this should work.


xx=data.frame(x=c(2, 10), y=c(2, 0), z=c(4, 3))
yy=xx[,2:3]
yy[yy!=0]=1
data.frame(x=xx[,1], yy)

bret



On 7/3/2012 9:18 PM, Manuel Spínola wrote:

Thank you Bret.

What if I need to leave out some variables from my data frame.  I have 22
variables and I need to leave the 2 first variables out of the condition.

Best,

Manuel

2012/7/3 Bret Collier 


Manuel,
Something like this should work for your example.

xx=data.frame(x=c(2, 10), y=c(2, 0))
xx[xx!=0]=1
xx
   x y
1 1 1
2 1 0

Bret


On 7/3/2012 8:12 PM, Manuel Spínola wrote:


Dear list members,

I want to recode a data frame but do it for several variables at the same
time.  I want to give all the values > or equal than 1 a value of 1 and
all
the remaining values (0) keep in 0.

data.frame: newdf

var1 var2 var3 var4
A   1  0 4
B   3  2 1
C   0  5 1

My real data frame has several more variables.

I am using the recode function from the epicalc package:

  recode(vars=newdf[, 2:4], old.value= newdf[, 2:4] >= 1, new.value=1)




Error en recode.default(vars = newdf[, 2:4], old.value = newdf[, 2:4] >=
  :
objeto '.data' no encontrado

I guess I am not setting the condition in a proper way.

Best,

Manuel



__**_
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/**listinfo/r-sig-ecology



__**_
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/**listinfo/r-sig-ecology







___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


Re: [R-sig-eco] Recode several variables with conditions in a data frame

2012-07-03 Thread Manuel Spínola
Thank you Bret.

What if I need to leave out some variables from my data frame.  I have 22
variables and I need to leave the 2 first variables out of the condition.

Best,

Manuel

2012/7/3 Bret Collier 

> Manuel,
> Something like this should work for your example.
>
> xx=data.frame(x=c(2, 10), y=c(2, 0))
> xx[xx!=0]=1
> xx
>   x y
> 1 1 1
> 2 1 0
>
> Bret
>
>
> On 7/3/2012 8:12 PM, Manuel Spínola wrote:
>
>> Dear list members,
>>
>> I want to recode a data frame but do it for several variables at the same
>> time.  I want to give all the values > or equal than 1 a value of 1 and
>> all
>> the remaining values (0) keep in 0.
>>
>> data.frame: newdf
>>
>> var1 var2 var3 var4
>> A   1  0 4
>> B   3  2 1
>> C   0  5 1
>>
>> My real data frame has several more variables.
>>
>> I am using the recode function from the epicalc package:
>>
>>  recode(vars=newdf[, 2:4], old.value= newdf[, 2:4] >= 1, new.value=1)
>>>
>>
>> Error en recode.default(vars = newdf[, 2:4], old.value = newdf[, 2:4] >=
>>  :
>>objeto '.data' no encontrado
>>
>> I guess I am not setting the condition in a proper way.
>>
>> Best,
>>
>> Manuel
>>
>>
>>
>> __**_
>> R-sig-ecology mailing list
>> R-sig-ecology@r-project.org
>> https://stat.ethz.ch/mailman/**listinfo/r-sig-ecology
>>
>>
> __**_
> R-sig-ecology mailing list
> R-sig-ecology@r-project.org
> https://stat.ethz.ch/mailman/**listinfo/r-sig-ecology
>



-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.ac.cr
mspinol...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative HTML version deleted]]

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


Re: [R-sig-eco] Recode several variables with conditions in a data frame

2012-07-03 Thread Bret Collier

Manuel,
Something like this should work for your example.

xx=data.frame(x=c(2, 10), y=c(2, 0))
xx[xx!=0]=1
xx
  x y
1 1 1
2 1 0

Bret

On 7/3/2012 8:12 PM, Manuel Spínola wrote:

Dear list members,

I want to recode a data frame but do it for several variables at the same
time.  I want to give all the values > or equal than 1 a value of 1 and all
the remaining values (0) keep in 0.

data.frame: newdf

var1 var2 var3 var4
A   1  0 4
B   3  2 1
C   0  5 1

My real data frame has several more variables.

I am using the recode function from the epicalc package:


recode(vars=newdf[, 2:4], old.value= newdf[, 2:4] >= 1, new.value=1)


Error en recode.default(vars = newdf[, 2:4], old.value = newdf[, 2:4] >=  :
   objeto '.data' no encontrado

I guess I am not setting the condition in a proper way.

Best,

Manuel



___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology



___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology


[R-sig-eco] Recode several variables with conditions in a data frame

2012-07-03 Thread Manuel Spínola
Dear list members,

I want to recode a data frame but do it for several variables at the same
time.  I want to give all the values > or equal than 1 a value of 1 and all
the remaining values (0) keep in 0.

data.frame: newdf

var1 var2 var3 var4
A   1  0 4
B   3  2 1
C   0  5 1

My real data frame has several more variables.

I am using the recode function from the epicalc package:

> recode(vars=newdf[, 2:4], old.value= newdf[, 2:4] >= 1, new.value=1)

Error en recode.default(vars = newdf[, 2:4], old.value = newdf[, 2:4] >=  :
  objeto '.data' no encontrado

I guess I am not setting the condition in a proper way.

Best,

Manuel

-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.ac.cr
mspinol...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[alternative HTML version deleted]]

___
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology