Re: [R] How to recode variables using base R

2010-03-30 Thread johannes rara
Thanks, you're a lifesaver. -J 2010/3/30 Henrique Dallazuanna : > Using lapply: > > as.data.frame(lapply(df, cut, breaks = c(-Inf, 3, 8, 16), labels = > c('x', 'y', 'z'))) > > > On Tue, Mar 30, 2010 at 10:14 AM, johannes rara > wrote: >> Thanks John and Henrique, my intention is to do this for

Re: [R] How to recode variables using base R

2010-03-30 Thread Henrique Dallazuanna
Using lapply: as.data.frame(lapply(df, cut, breaks = c(-Inf, 3, 8, 16), labels = c('x', 'y', 'z'))) On Tue, Mar 30, 2010 at 10:14 AM, johannes rara wrote: > Thanks John and Henrique, my intention is to do this for A, B and C > (all at once), so I'll have to wrap your solution into lapply or for

Re: [R] How to recode variables using base R

2010-03-30 Thread johannes rara
Thanks John and Henrique, my intention is to do this for A, B and C (all at once), so I'll have to wrap your solution into lapply or for loop? -J 2010/3/30 Henrique Dallazuanna : > You could try this also: > > cut(df$A, c(-Inf, 3, 8), labels = c('x', 'y')) > > On Tue, Mar 30, 2010 at 8:30 AM, joh

Re: [R] How to recode variables using base R

2010-03-30 Thread Henrique Dallazuanna
You could try this also: cut(df$A, c(-Inf, 3, 8), labels = c('x', 'y')) On Tue, Mar 30, 2010 at 8:30 AM, johannes rara wrote: > Hi, > > Is there an efficient way recoding variables in a data.frame using > base R? My purpose is to create > new variables and attach them into old data.frame. The ba

Re: [R] How to recode variables using base R

2010-03-30 Thread John Fox
Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of johannes rara > Sent: March-30-

[R] How to recode variables using base R

2010-03-30 Thread johannes rara
Hi, Is there an efficient way recoding variables in a data.frame using base R? My purpose is to create new variables and attach them into old data.frame. The basic idea is shown below, but how to create recoding for A, B and C and assing them into new variables? df <- data.frame(A = c(1:5), B = c