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
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
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")
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
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
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
> 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
> 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
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
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
> 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
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
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
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"] <- "
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
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
> 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
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
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
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/
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
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
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
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
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
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, 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
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 ...
)
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
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
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
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
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
$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:
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
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
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
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
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
>
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
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
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
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
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
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
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
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:
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
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
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]
>
>
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
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
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
> -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
> -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
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
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
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
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
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
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
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
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
##
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
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,
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,{
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 ->
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
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
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
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
-- 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
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
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
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
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,
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
--
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
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
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
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
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
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
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?
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,
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
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
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
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
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
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
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
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
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
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
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"
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
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
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
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 - 100 of 119 matches
Mail list logo