Re: [R] Recoding variables in R

2018-05-23 Thread Lisa van der Burgh
Thank you all for your help, it worked! Op 23 mei 2018 om 19:27 heeft marta azores mailto:martazo...@gmail.com>> het volgende geschreven: Try that code NewDF<-DF[!DF$Anxiolytics==1,] 2018-05-23 10:14 GMT+00:00 Lisa van der Burgh mailto:lisavdbu...@hotmail.com>>: Hi all, I have a very genera

Re: [R] Recoding variables in R

2018-05-23 Thread Rui Barradas
Hello, See if this inspires you. set.seed(1962) DF <- data.frame(Anxiolytics = factor(sample(c(0, 2, NA), 1000, TRUE), levels = 0:2)) summary(DF$Anxiolytics) DF$Anxiolytics <- droplevels(DF$Anxiolytics) summary(DF$Anxiolytics) DF$Anxiolytics <- factor(DF$Anxiolytics, labels = 0:1) summary(D

Re: [R] Recoding variables in R

2018-05-23 Thread William Dunlap via R-help
It looks like your data has class "factor". If you call factor() on a factor variable, without supplying an explicit 'levels' argument it produces a new factor variable without any levels not present in the input factor. E.g., > fOrig <- factor(c(NA,"A","B","D",NA,"D"), levels=c("D","C","B","A")

[R] Recoding variables in R

2018-05-23 Thread Lisa van der Burgh
Hi all, I have a very general question and I think for you maybe very easy, but I am not able to solve it. I have a dataset and that dataset contains the variable Anxiolytics. This variable is coded as 0, 1, 2. The variable looks as follows: > summary(DF$Anxiolytics) 01 2

Re: [R] recoding responses in a numeric variable

2017-01-07 Thread Jeff Newmiller
Please read the Posting Guide mentioned at the bottom of this and every message. In particular, send your email in plain text format so we get to see what you saw (the mailing list strips out HTML formatting in most cases). Also please work to make your examples reproducible... e.g. give all st

[R] recoding responses in a numeric variable

2017-01-07 Thread Licia Biotti
Hello, I am working with a dataset in R studio, and I have created a numeric variable which I have called fear by using a factor variable (called vn35). Here is the piece of code: fear<-gles_reduced$vn35 levels(fear) table(fear, as.numeric(fear), exclude=NULL) Then I have coded the levels "don't

Re: [R] Recoding lists of categories of a variable

2016-10-11 Thread Bert Gunter
> Hardly a showstopper though; we're in timtowdi territory here and we're > allowed a bit of personal preference. Absolutely. I appreciate your constructive comments, however. Cheers, Bert __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and mo

Re: [R] Recoding lists of categories of a variable

2016-10-11 Thread S Ellison
> If you are concerned about missing levels -- which I agree is legitimate -- > then > the following simple modification works (for > **factors** of course): > > > d <- factor(letters[1:2],levels= letters[1:3]) d > [1] a b > Levels: a b c > > f <- factor(d,levels = levels(d), labels = LETTERS[3:1

Re: [R] Recoding lists of categories of a variable

2016-10-11 Thread peter dalgaard
On 11 Oct 2016, at 01:32 , S Ellison wrote: >> Well, I think that's kind of overkill. > Depends whether you want to recode all or some, and how robust you want the > answer to be. > recode() allows you to recode a few levels of many, without dependence on > level ordering; that's kind of neat

Re: [R] Recoding lists of categories of a variable

2016-10-10 Thread Bert Gunter
Still overkill, I believe. " Unlike using the numeric levels, that doesn't fail if some of the levels I expect are absent; it only fails (and does so visibly) when there's a value in there that I haven't assigned a coding to. So it's a tad more robust. " If you are concerned about missing level

Re: [R] Recoding lists of categories of a variable

2016-10-10 Thread S Ellison
> Well, I think that's kind of overkill. Depends whether you want to recode all or some, and how robust you want the answer to be. recode() allows you to recode a few levels of many, without dependence on level ordering; that's kind of neat. tbh, though, I don't use recode() a lot; I generall

Re: [R] Recoding lists of categories of a variable

2016-10-10 Thread Jim Lemon
Hi Margaret, This may be a misunderstanding of your request, but what about: mydata<-data.frame(oldvar=paste("topic",sample(1:9,20,TRUE),sep="")) mydata$newvar<-sapply(mydata$oldvar,gsub,"topic.","parenttopic") Jim On Tue, Oct 11, 2016 at 1:56 AM, MACDOUGALL Margaret wrote: > Hello > > The R c

Re: [R] Recoding lists of categories of a variable

2016-10-10 Thread MACDOUGALL Margaret
r-help-boun...@r-project.org] On Behalf Of > MACDOUGALL Margaret > Sent: Monday, October 10, 2016 10:56 AM > To: r-help@r-project.org > Subject: [R] Recoding lists of categories of a variable > > Hello > > The R code > mydata$newvar[oldvar = "topic1"] <- &qu

Re: [R] Recoding lists of categories of a variable

2016-10-10 Thread Fox, John
10, 2016 10:56 AM > To: r-help@r-project.org > Subject: [R] Recoding lists of categories of a variable > > Hello > > The R code > mydata$newvar[oldvar = "topic1"] <- "parenttopic" That should be mydata$newvar[oldvar == "topic1"] <- "

Re: [R] Recoding lists of categories of a variable

2016-10-10 Thread Bert Gunter
Well, I think that's kind of overkill. Assuming "oldvar" is a factor in the data frame mydata, then the following shows how to do it: > set.seed(27) > d <- data.frame(a = sample(c(letters[1:3],NA),15,replace = TRUE)) > d a 1 2 a 3 4 b 5 a 6 b 7 a 8 a 9 a 10

Re: [R] Recoding lists of categories of a variable

2016-10-10 Thread David L Carlson
10 8 7 7 11 topic 10topic 11topic 12topic 13topic 15topic 16 topic 17topic 18 8 10 9 13 19 12 11 3 topic 19topic 20 18

Re: [R] Recoding lists of categories of a variable

2016-10-10 Thread S Ellison
> Is there a convenient way to edit this code to allow me to recode a list of > categories 'topic 1', 'topic 9' and 'topic 14', say, of the the old variable > 'oldvar' > as 'parenttopic' by means of the new variable 'newvar', while also mapping > system missing values to system missing values? Yo

[R] Recoding lists of categories of a variable

2016-10-10 Thread MACDOUGALL Margaret
Hello The R code mydata$newvar[oldvar = "topic1"] <- "parenttopic" is intended to recode the category 'topic 1' of the old varaible 'oldvar' a new category label 'parenttopic' by defining the new variable 'newvar'. Is there a convenient way to edit this code to allow me to recode a list of ca

Re: [R] recoding genetic information using gsub

2014-12-05 Thread William Dunlap
Does the following do what you want? > raw <- c("A/B", " /B", "A/", "/ ") > tmp <- sub("^ */", "./", raw) > cleaned <- sub("/ *$", "/.", tmp) > cleaned [1] "A/B" "./B" "A/." "./." (The " *" is to allow optional spaces before or after the slash.) Bill Dunlap TIBCO Software wdunlap tibco.com On F

Re: [R] recoding genetic information using gsub

2014-12-05 Thread Martin Morgan
On 12/5/2014 11:24 AM, Kate Ignatius wrote: I have genetic information for several thousand individuals: A/T T/G C/G etc For some individuals there are some genotypes that are like this: A/, C/, T/, G/ or even just / which represents missing and I want to change these to the following: A/ A/

Re: [R] recoding genetic information using gsub

2014-12-05 Thread Sarah Goslee
Hi, Briefly, you need to read about regular expressions. It's possible to be incredibly specific, and even to do what you want with a single line of code. It's hard to be certain of exactly what you need, though, without a reproducible example. See inline for one possibility. On Fri, Dec 5, 2014

[R] recoding genetic information using gsub

2014-12-05 Thread Kate Ignatius
I have genetic information for several thousand individuals: A/T T/G C/G etc For some individuals there are some genotypes that are like this: A/, C/, T/, G/ or even just / which represents missing and I want to change these to the following: A/ A/. C/ C/. G/ G/. T/ T/. / ./. /A ./A /C ./C /G

Re: [R] Recoding in R conditioned on a certain value.

2014-04-05 Thread David Winsemius
On Apr 5, 2014, at 9:51 AM, Kate Ignatius wrote: > I'm trying to work out the average of a certain value by chromosome. > I've done the following, but it doesn't seem to work: > > Say, I want to find average AD for chromosome 1 only and paste the > value next to all the positions on chromosome 1

[R] Recoding in R conditioned on a certain value.

2014-04-05 Thread Kate Ignatius
I'm trying to work out the average of a certain value by chromosome. I've done the following, but it doesn't seem to work: Say, I want to find average AD for chromosome 1 only and paste the value next to all the positions on chromosome 1: sam$mmad[sam$chrom == '1'] <- (sam$ad)/(colSums(sam[c(1:nr

Re: [R] recoding table dimensions interactively

2014-01-09 Thread Michael Friendly
2 1 0:6 0 0 0 0 0 1 0:8 0 0 0 0 0 1 1:1 3 0 0 0 4 0 1:2 0 2 0 0 2 1 1:3 0 0 0 0 0 0 1:4 0 2 0 0 0 0 1:6 0 0 0 0 0 0 1:8 0 0 0 0 0 0 Bill Dunlap Spotfire, TIBCO

Re: [R] recoding table dimensions interactively

2014-01-09 Thread Hadley Wickham
Hi Michael, It's pretty easy with reshape: library(reshape2) ucbm <- melt(UCBAdmissions) acast(ucbm, Admit + Gender ~ Dept) acast(ucbm, Admit ~ Dept + Gender) acast(ucbm, Admit + Dept + Gender ~ .) # You can also do aggregations acast(ucbm, Admit ~ Dept, fun = sum) Hadley On Thu, Jan 9, 2014 a

Re: [R] recoding table dimensions interactively

2014-01-09 Thread William Dunlap
re, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of Michael Friendly > Sent: Thursday, January 09, 2014 7:14 AM > To: R-help > Subject: [R] recoding table dimensions int

[R] recoding table dimensions interactively

2014-01-09 Thread Michael Friendly
Given a 3+ way table, I'd like a simple, elegant way to flatten the table to a two-way table, with some variables joined interactively to form the rows and others forming the columns. For example, starting with > str(UCBAdmissions) table [1:2, 1:2, 1:6] 512 313 89 19 353 207 17 8 120 205 ...

Re: [R] Recoding variables based on reference values in data frame

2013-07-03 Thread arun
)  dim(res1New1)<- dim(res1New) identical(res1New1,res2) #[1] TRUE A.K. - Original Message ----- From: kathleen askland To: r-help@r-project.org Cc: Sent: Tuesday, July 2, 2013 4:46 PM Subject: [R] Recoding variables based on reference values in data frame I'm new to R (pre

Re: [R] Recoding variables based on reference values in data frame

2013-07-02 Thread Rui Barradas
Hello, If you have read in the data as factors (stringsAsFactors = TRUE, the default), change the function to the following. fun <- function(x){ x[x %in% c("nc", "_")] <- NA MM <- paste0(as.character(x[1]), as.character(x[1])) # Major Major Mm <- paste0(as.character(x

Re: [R] Recoding variables based on reference values in data frame

2013-07-02 Thread Rui Barradas
Hello, I'm not sure I understood, but try the following. Kgeno <- read.table(text = " SNP_ID SNP1 SNP2 SNP3 SNP4 Maj_Allele C G C A Min_Allele T A T G ID1 CC GG CT AA ID2 CC GG CC AA ID3 CC GGncAA ID4 _ _ _ _ ID5 CC GG CC AA ID6 CC GG CC

[R] Recoding variables based on reference values in data frame

2013-07-02 Thread kathleen askland
I'm new to R (previously used SAS primarily) and I have a genetics data frame consisting of genotypes for each of 300+ subjects (ID1, ID2, ID3, ...) at 3000+ genetic locations (SNP1, SNP2, SNP3...). A small subset of the data is shown below: SNP_ID SNP1 SNP2 SNP3 SNP4 Maj_Allele C G C A Min_A

Re: [R] recoding variables again :(

2013-01-30 Thread nalluri pratap
dat1$VARNEW<-rep("unknown",nrow(dat1)) dat1$VARNEW[dat1$RES_STA=="X" & dat1$BIRTHPLACE %in% c("AG","AI","AR","BE","ZH")]<-"swiss" --- On Wed, 30/1/13, arun wrote: From: arun Subject: Re: [R] recoding va

Re: [R] recoding variables again :(

2013-01-30 Thread arun
$RES_STA=="X" & dat1$BIRTHPLACE%in%c("AG","AI","AR","BE","ZH"),"swiss","unknown") A.K. - Original Message - From: David Studer To: r-help@r-project.org Cc: Sent: Wednesday, January 30, 2013 4:42 AM Subject:

Re: [R] recoding variables again :(

2013-01-30 Thread Jorge I Velez
Hi David, Check ?"%in%" for a simpler approach. Regards, Jorge.- On Wed, Jan 30, 2013 at 8:42 PM, David Studer <> wrote: > Hello everybody! > > I have again a rather simple question concerning recoding of variables: > > I have a variable/data-frame column BIRTHPLACE containing abbreviations

[R] recoding variables again :(

2013-01-30 Thread David Studer
Hello everybody! I have again a rather simple question concerning recoding of variables: I have a variable/data-frame column BIRTHPLACE containing abbreviations of the 26 swiss counties (AG, AI, AR, BE, ZH, ... ) as well as international country codes (USA, GER, ESP, etc.) and another variable RE

Re: [R] Recoding variables (without recode() )

2013-01-25 Thread PIKAL Petr
Hi > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of David Studer > Sent: Friday, January 25, 2013 9:28 AM > To: r-help@r-project.org > Subject: [R] Recoding variables (without recode() ) > > Hi everybo

[R] Recoding variables (without recode() )

2013-01-25 Thread David Studer
Hi everybody! I have a rather simple question: # play data persId<-c(1,2,3,1,4,5,2) varA<-c(11,12,13,12,14,15,10) df<-as.data.frame(cbind(persId, varA)) Now I'd like to create a new columns (df$new) according to the value of df$VarA. For example df$new1 should be 1 if df$varA==2 or df$new2 shou

Re: [R] Recoding categorical gender variable into numeric factors

2012-09-05 Thread David L Carlson
ault, R orders the character strings alphabetically before converting to factors so "Female" becomes 1 and "Male" becomes 2. -- David L Carlson Associate Professor of Anthropology Texas A&M University College Station, TX 77843-4352 >

Re: [R] Recoding categorical gender variable into numeric factors

2012-09-05 Thread Ista Zahn
Hi Conrad, On Wed, Sep 5, 2012 at 3:14 PM, Conradsb wrote: > I currently have a data set in which gender is inputed as "Male" and "Female" > , and I'm trying to convert this into "1" and "0". This is usually not necessary, and makes things more confusing. "Male" and "Female" is clear and self-ex

[R] Recoding categorical gender variable into numeric factors

2012-09-05 Thread Conradsb
I currently have a data set in which gender is inputed as "Male" and "Female" , and I'm trying to convert this into "1" and "0". I found a website which reccomended using two commands: data$scode[data$sex=="M"] <- "1" data$scode[data$sex=="F"] <- "2" to convert to numbers, and: data$scode <- fa

Re: [R] Recoding numeric value

2012-05-19 Thread Giggles
Thank you very much!! On May 18, 2:22 pm, David Winsemius wrote: > On May 18, 2012, at 3:26 PM, Giggles wrote: > > > I am a newbie and can't figure out how to recode a numeric value. In > > my data (pharm311), I have a column called "explain" and I need to > > find all the 6's and change it to NA

Re: [R] Recoding numeric value

2012-05-19 Thread Giggles
Thanks so much! I thought R places NA for missing values. I'll have to read up on it more. Thanks again! On May 18, 2:23 pm, Marc Schwartz wrote: > On May 18, 2012, at 2:26 PM, Giggles wrote: > > > I am a newbie and can't figure out how to recode a numeric value. In > > my data (pharm311), I have

Re: [R] Recoding numeric value

2012-05-18 Thread Marc Schwartz
On May 18, 2012, at 2:26 PM, Giggles wrote: > I am a newbie and can't figure out how to recode a numeric value. In > my data (pharm311), I have a column called "explain" and I need to > find all the 6's and change it to NA (blank). Could someone help? > > I'm sorry if this is too basic, I starte

Re: [R] Recoding numeric value

2012-05-18 Thread David Winsemius
On May 18, 2012, at 3:26 PM, Giggles wrote: I am a newbie and can't figure out how to recode a numeric value. In my data (pharm311), I have a column called "explain" and I need to find all the 6's and change it to NA (blank). Could someone help? is.na(pharm311$explain) <- pharm311$explain==6

[R] Recoding numeric value

2012-05-18 Thread Giggles
I am a newbie and can't figure out how to recode a numeric value. In my data (pharm311), I have a column called "explain" and I need to find all the 6's and change it to NA (blank). Could someone help? I'm sorry if this is too basic, I started messing with R this week and got stuck with this probl

Re: [R] Recoding multiple TRUE/FALSE columns into a single list of TRUE columns

2011-12-25 Thread David Epstein
Jim, Wow, that does it! I think I can use strsplit and unlist to convert the string of row names into a R list. thank you! -david __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http:

Re: [R] Recoding multiple TRUE/FALSE columns into a single list of TRUE columns

2011-12-25 Thread jim holtman
Try this: > x <- read.table(text = " P1 P2 P3 P4 + 1 0011 + 2 0111 + 3 1000 + 4 0000 + 5 1111 ", header = TRUE) > labs <- apply(x, 1, function(.row){ + indx <- which(.row == 1) + if (length(indx) > 0) return(pas

[R] Recoding multiple TRUE/FALSE columns into a single list of TRUE columns

2011-12-25 Thread David Epstein
Hi everyone, I need to recode multiple columns in a dataframe into a single column in a variety of different ways. Often the values will be TRUE/FALSE and I want a list of the columns that are true as in the Result column below: P1 P2 P3 P4 Result 1 0011P3,P4 2

Re: [R] Recoding observations in all columns of a data frame.

2011-08-31 Thread Jorge I Velez
Dear CH, Try example[example == 999] <- NA example HTH, Jorge On Wed, Aug 31, 2011 at 4:48 AM, C.H. <> wrote: > Dear all, > > Suppose I have a data frame like this: > > [code] > var1 <- c(1,999,2) > var2 <- c(999,1,2) > var3 <- c(1,2,999) > example <- data.frame(var1,var2,var3) > [/code] > >

[R] Recoding observations in all columns of a data frame.

2011-08-31 Thread C.H.
Dear all, Suppose I have a data frame like this: [code] var1 <- c(1,999,2) var2 <- c(999,1,2) var3 <- c(1,2,999) example <- data.frame(var1,var2,var3) [/code] I want to replace all 999 to NA in all observations in all columns. I know how to do it in each individual column. [code] example$var1[e

Re: [R] Recoding Multiple Variables in a Data Frame in One Step

2011-07-25 Thread Peter Ehlers
On 2011-07-25 15:48, William Dunlap wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius Sent: Monday, July 25, 2011 3:39 PM To: Anthony Damico Cc: r-help@r-project.org Subject: Re: [R] Recoding Multiple

Re: [R] Recoding Multiple Variables in a Data Frame in One Step

2011-07-25 Thread David Winsemius
On Jul 25, 2011, at 6:48 PM, William Dunlap wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org ] On Behalf Of David Winsemius Sent: Monday, July 25, 2011 3:39 PM To: Anthony Damico Cc: r-help@r-project.org Subject: Re: [R] Recoding

Re: [R] Recoding Multiple Variables in a Data Frame in One Step

2011-07-25 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of William Dunlap > Sent: Monday, July 25, 2011 3:49 PM > To: David Winsemius; Anthony Damico > Cc: r-help@r-project.org > Subject: Re: [R] Recoding Multipl

Re: [R] Recoding Multiple Variables in a Data Frame in One Step

2011-07-25 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of David Winsemius > Sent: Monday, July 25, 2011 3:39 PM > To: Anthony Damico > Cc: r-help@r-project.org > Subject: Re: [R] Recoding Multiple Variables in a D

Re: [R] Recoding Multiple Variables in a Data Frame in One Step

2011-07-25 Thread David Winsemius
On Jul 21, 2011, at 8:06 PM, Anthony Damico wrote: Hi, I can't for the life of me find how to do this in base R, but I'd be surprised if it's not possible. I'm just trying to replace multiple columns at once in a data frame. #load example data data(api) #this displays the three columns and

[R] Recoding Multiple Variables in a Data Frame in One Step

2011-07-21 Thread Anthony Damico
Hi, I can't for the life of me find how to do this in base R, but I'd be surprised if it's not possible. I'm just trying to replace multiple columns at once in a data frame. #load example data data(api) #this displays the three columns and eight rows i'd like to replace apiclus1[ apiclus1$meals

Re: [R] Recoding several variables into one use the most recent data

2011-06-27 Thread David Winsemius
On Jun 27, 2011, at 12:56 PM, Christopher Desjardins wrote: Hi, I have the following data management issue. I am trying to combine multiple years of ethnicity data into one variable called ethnic. The data looks similar to the following idethnic07ethnic08 ethnic09ethnic10 1

[R] Recoding several variables into one use the most recent data

2011-06-27 Thread Christopher Desjardins
Hi, I have the following data management issue. I am trying to combine multiple years of ethnicity data into one variable called ethnic. The data looks similar to the following idethnic07ethnic08 ethnic09ethnic10 1 1 1 11 2 1

Re: [R] recoding a data in different way: please help

2011-02-18 Thread Umesh Rosyara
Sorry to bother all of you, but simple things are being complicated these days to me. Thank you so much Umesh R _ From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: Friday, February 18, 2011 12:15 AM Cc: r-help@r-project.org Subject: Re: [R] recoding a data in dif

Re: [R] recoding a data in different way: please help

2011-02-18 Thread Umesh Rosyara
8, 2011 12:28 AM Cc: r-help@r-project.org Subject: Re: [R] recoding a data in different way: please help Hi: This is as far as I could get: df <- read.table(textConnection(" Individual Parent1 Parent2 mark1 mark2 10 0 12 11 20 0

Re: [R] recoding a data in different way: please help

2011-02-17 Thread Dennis Murphy
Hi: This is as far as I could get: df <- read.table(textConnection(" Individual Parent1 Parent2 mark1 mark2 10 0 12 11 20 0 11 22 30 0 13 22 40 0 13 11 51 2

Re: [R] recoding a data in different way: please help

2011-02-17 Thread Joshua Wiley
Dear Umesh, I could not figure out exactly what your recoding scheme was, so I do not have a specific solution for you. That said, the following functions may help you get started. ?ifelse # vectorized and different from using if () statements ?if # ?Logic ## logical operators for your tests ##

[R] recoding a data in different way: please help

2011-02-17 Thread Umesh Rosyara
Dear R users The following question looks simple but I have spend alot of time to solve it. I would highly appeciate your help. I have following dataset from family dataset : Here we have individuals and their two parents and their marker scores (marker1, marker2,and so on). 0 means t

Re: [R] Recoding using the memisc package

2011-02-13 Thread Peter Ehlers
On 2011-02-13 07:05, Shige Song wrote: Dear All, I am trying to recode a variable using the functions provided by "memisc" package. Actually I am following the examples on page 9-10 of the vignette: -- d.fig<- within(d.fig,

Re: [R] Recoding using the memisc package

2011-02-13 Thread Dieter Menne
Shige Song wrote: > > Dear All, > > I am trying to recode a variable using the functions provided by > "memisc" package. Actually I am following the examples on page 9-10 of > the vignette: > > -- > d.fig <- within(d.fig,{

[R] Recoding using the memisc package

2011-02-13 Thread Shige Song
Dear All, I am trying to recode a variable using the functions provided by "memisc" package. Actually I am following the examples on page 9-10 of the vignette: -- d.fig <- within(d.fig,{ sev <- recode(sev, 1 ->

Re: [R] Recoding -- test whether number begins with a certain number

2010-11-03 Thread Barry Rowlingson
On Wed, Nov 3, 2010 at 10:01 AM, Marcel Gerds wrote: >  Dear R community, > > I have a question concerning recoding of a variable. I have a data set > in which there is a variable devoted to the ISCO code describing the > occupation of this certain individual > (http://www.ilo.org/public/english/b

[R] Recoding -- test whether number begins with a certain number

2010-11-03 Thread Marcel Gerds
Dear R community, I have a question concerning recoding of a variable. I have a data set in which there is a variable devoted to the ISCO code describing the occupation of this certain individual (http://www.ilo.org/public/english/bureau/stat/isco/isco88/major.htm). Every type of occupation begi

[R] recoding problem

2010-07-23 Thread Heiman, Thomas J.
Hi, I am trying to recode the output from a matrix(here is a small snippet of it): HGlt10RawPerc2008[1:20] [1] -5 0 -1 -1 0 2 3 -5 -2 0 2 0 1 -2 3 0 4 1 4 2 Her

Re: [R] Recoding dates to session id in a longitudinal dataset

2010-06-27 Thread JP Bogers
Hi Jim, Thanks for the answer. What I actually want is a session sequence 1,2,... per patient. This would be very useful to look at trends of HPV infections from the first to the second sample etc. It would also allow me to extract the HPV data of the first sample (session 1). Thx JP On Sat, Ju

Re: [R] Recoding dates to session id in a longitudinal dataset

2010-06-26 Thread John-Paul Bogers
-- Forwarded message -- From: John-Paul Bogers Date: Sat, Jun 26, 2010 at 10:14 PM Subject: Re: [R] Recoding dates to session id in a longitudinal dataset To: jim holtman Dear Jim, he data concerns HPV screening data. The data looks as follows pat1 sampledate1 HPV16 0.3 pat2

[R] Recoding session date into session id in a longitudinal dataset

2010-06-26 Thread JP Bogers
Hi, I'm fairly new to R but I have a large dataset (30 obs) containing patient material. Some patients came 2-9 times during the three year observation period. The patients are identified by a unique idnr, the sessions can be distinguished using the session date. How can I recode the date of t

[R] Recoding dates to session id in a longitudinal dataset

2010-06-26 Thread John-Paul Bogers
Hi, I'm fairly new to R but I have a large dataset (30 obs) containing patient material. Some patients came 2-9 times during the three year observation period. The patients are identified by a unique idnr, the sessions can be distinguished using the session date. How can I recode the date of t

Re: [R] recoding variables-recode not working

2010-04-08 Thread Vlatka Matkovic Puljic
0 1 and more >>> [7] 1 and more 1 and more 1 and more 1 and more >>> Levels: 0 1 and more >>> >>> I hope this helps, >>> John >>> >>> >>> John Fox >>> Senator William McMas

Re: [R] recoding variables-recode not working

2010-04-08 Thread David Winsemius
tario, 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 Vlatka Matkovic Puljic Sent: April-07-10 1:31 PM To: r-help@r-project.org Subject: [R] recoding variables-recode not working Hi,

Re: [R] recoding variables-recode not working

2010-04-08 Thread Vlatka Matkovic Puljic
vels: 0 1 and more > > I hope this helps, > John > > > John Fox > Senator William McMaster > Professor of Social Statistics > Department of Sociology > McMaster University > Hamilton, Ontario, Canada > web: socserv.mcmaster.ca/jfox &g

Re: [R] recoding variables-recode not working

2010-04-07 Thread John Fox
-- John Fox Senator William McMaster 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-p

Re: [R] recoding variables-recode not working

2010-04-07 Thread David Winsemius
On Apr 7, 2010, at 1:50 PM, Vlatka Matkovic Puljic wrote: atomic [1:1578] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, "levels")= chr "0=0,1:33=1" Can you go back to where you got this data and start over? You have made something that looks quite strange. It appears to be neither a vector of mode a

Re: [R] recoding variables-recode not working

2010-04-07 Thread David Winsemius
On Apr 7, 2010, at 1:31 PM, Vlatka Matkovic Puljic wrote: Hi, I have numerical variable that I want to recode into categories '0' and '1 and more' and do analysis with that data. I have tried various of possibilities to do so, but I am sucked and nothing is working. recode(Q12, "0='A';1

Re: [R] recoding variables-recode not working

2010-04-07 Thread Vlatka Matkovic Puljic
atomic [1:1578] 0 0 0 0 0 0 0 0 0 0 ... - attr(*, "levels")= chr "0=0,1:33=1" 2010/4/7 David Winsemius > > On Apr 7, 2010, at 1:31 PM, Vlatka Matkovic Puljic wrote: > > Hi, >> >> I have numerical variable that I want to recode into categories '0' and '1 >> and more' and do analysis with that d

[R] recoding variables-recode not working

2010-04-07 Thread Vlatka Matkovic Puljic
Hi, I have numerical variable that I want to recode into categories '0' and '1 and more' and do analysis with that data. I have tried various of possibilities to do so, but I am sucked and nothing is working. recode(Q12, "0='A';1:30='B'") cut(Q12, breaks=c(0,1,30), lables=c('0', '1 and more')) ca

Re: [R] Recoding Variables in R

2010-01-28 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 Mathew, Abraham T > Sent: Janu

[R] Recoding Variables in R

2010-01-28 Thread Mathew, Abraham T
VAR 980490 Some people have suggested placing new limits on foreign imports in order to protect American jobs. Others say that such limits would raise consumer prices and hurt American exports. Do you FAVOR or OPPOSE placing new limits on imports, or haven't you thought much about this?

Re: [R] Recoding factor labels that are lists into first element of list

2009-12-11 Thread Gabor Grothendieck
Or this which removing the comma and everything thereafter in each level that has a comma: levels(x$a) <- sub(",.*", "", levels(x$a)) On Fri, Dec 11, 2009 at 5:21 AM, jim holtman wrote: > try this: > >> x <- data.frame(a=c('cat', 'cat,dog', 'dog', 'dog,cat')) >> x >        a > 1     cat > 2 cat,

Re: [R] Recoding factor labels that are lists into first element of list

2009-12-11 Thread jim holtman
try this: > x <- data.frame(a=c('cat', 'cat,dog', 'dog', 'dog,cat')) > x a 1 cat 2 cat,dog 3 dog 4 dog,cat > levels(x$a) [1] "cat" "cat,dog" "dog" "dog,cat" > # change the factors > x$a <- factor(sapply(strsplit(as.character(x$a), ','), '[[', 1)) > x a 1 cat 2 cat 3 dog

[R] Recoding factor labels that are lists into first element of list

2009-12-10 Thread Jennifer Walsh
Hi all, I've Googled far and wide but don't think I know the correct terms to search for to find an answer. I have a massive dataset where one of the factors is made up of both individual items and lists of items (for example, "cat" and "cat, dog, bird"). I would like to recode this facto

[R] recoding strings containing colons

2009-07-08 Thread Donald Braman
Curious to know if recode can work with strings containing colons. I haven't gotten it to work yet, but perhaps there is a way? Donald Braman http://www.culturalcognition.com/braman/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/lis

Re: [R] recoding charactor variables with special charactors

2009-07-02 Thread John Kane
First of all try str(socia) and see what the structure of the data is. R seems to be interpreting that character string as a format If I am reading the error message correctly. --- On Wed, 7/1/09, Chris Anderson wrote: > From: Chris Anderson > Subject: [R] recoding charactor var

Re: [R] recoding charactor variables with special charactors

2009-07-01 Thread Henrique Dallazuanna
It's because the levels of factor, don't characters: f <- factor(c("AAA's", "B(s)", "CCC")) levels(f)[levels(f) == "AAA's"] <- "AA" On Wed, Jul 1, 2009 at 4:43 PM, Chris Anderson wrote: > I have a several character variables that I need to recode, but some of > them have special characters

[R] recoding charactor variables with special charactors

2009-07-01 Thread Chris Anderson
I have a several character variables that I need to recode, but some of them have special characters like single quote or ( ). How tell R to ignore these special characters so I can rename them? Below is the error message I am getting. social$FamilySupport[social$FamilySupport=="Mr. XXXs' exte

Re: [R] Recoding

2008-07-03 Thread Agustin Lobo
Thanks. This is a simple and efficient solution for the case in which the elements of the vector "values" are integers (which is often the case as in the example that came to my mind). Nevertheless, let me suggest having a more comprehensive function recode in base, as this is a very usual and we

Re: [R] Recoding a variable

2008-07-03 Thread Peter Dalgaard
John Fox wrote: Dear Spencer, In addition to the approaches already suggested, there is the recode() function in the car package. Or this way: levels(ftpain) <- list( none="none", intermediate=c("mild", "medium"), severe="severe") Or this (not quite as general): level

Re: [R] Recoding a variable

2008-07-03 Thread John Fox
Dear Spencer, In addition to the approaches already suggested, there is the recode() function in the car package. Regards, John John Fox, Professor Department of Sociology McMaster University Hamilton ON Canada L8S 4M4 web: socserv.mcmaster.ca/jf

Re: [R] Recoding a variable

2008-07-03 Thread Stephan Kolassa
internet.use[internet.use=="Never" | internet.use=="Don't know"] <- 0 internet.use[internet.use!=0] <- 1 HTH, Stephan Spencer schrieb: Hi All, I'm relatively new to R. I have a variable, "internet use," which ranges from "Almost everyday, "Several times a week," "Several times a month," "S

Re: [R] Recoding a variable

2008-07-03 Thread jim holtman
Here is an example of a way to do it: > x <- sample(LETTERS[1:5], 20, TRUE) > x [1] "D" "E" "A" "B" "A" "E" "A" "E" "A" "E" "C" "D" "A" "E" "D" "E" "A" "C" "B" "B" > # new vector with "D" and "E" = 0 > new.x <- ifelse((x == "D") | (x == "E"), 0, 1) > cbind(x,new.x) x new.x [1,] "D" "0"

[R] Recoding a variable

2008-07-03 Thread Spencer
Hi All, I'm relatively new to R. I have a variable, "internet use," which ranges from "Almost everyday, "Several times a week," "Several times a month," "Seldom," "Never," and "Don't know." I want to recode this data into a new variable, say "use.internet," such that I have a dichotomous var

Re: [R] Recoding

2008-06-28 Thread jgarcia
Agustín; also you can do: > v <- c(1,1,1,2,3,4,1,10,3) > dict <- cbind(c(1,2,3),c(1001,1002,1003)) > v <- ifelse(!is.na(match(v,dict)),dict[match(v,dict),2],v) > v [1] 1001 1001 1001 1002 10034 1001 10 1003 Javier - > Dear Agustin, > > Perhaps > > v1 <- c(1,1,1,2,3,4,1,10,3) > dpu

Re: [R] Recoding

2008-06-27 Thread Marc Schwartz
on 06/27/2008 01:41 PM Agustin Lobo wrote: Hi! Given a vector (or a factor within a df),i.e. v1 <- c(1,1,1,2,3,4,1,10,3) and a dictionary cbind(c(1,2,3),c(1001,1002,1003)) is there a function (on the same line than recode() in car) to get v2 as c(1001,1001,1001,1002,1003,4,1001,10,1003) ? I'm

Re: [R] Recoding

2008-06-27 Thread Daniel Folkinshteyn
if there's nothing specific for it, you could probably do it with merge? on 06/27/2008 02:41 PM Agustin Lobo said the following: Hi! Given a vector (or a factor within a df),i.e. v1 <- c(1,1,1,2,3,4,1,10,3) and a dictionary cbind(c(1,2,3),c(1001,1002,1003)) is there a function (on the same lin

  1   2   >