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")
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
> 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
Thank you for the valued suggestions in response to my query.
Margaret
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.
-Original Message-
From: Fox, John [mailto:j...@mcmaster.ca]
Sent: 10 October 2016 20:32
To: MACDOUGA
Dear Margaret,
You've had one suggestion of an alternative for recoding variables, but in
addition your code is in error (see below).
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
> MACDOUGALL Margaret
> Sent: Monday, October 10, 2016 10:56 AM
> T
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
Your code suggests that you do not understand R or what you are doing. The line
mydata$newvar[oldvar = "topic1"] <- "parenttopic"
does not recode cases where oldvar is "topic1", it creates a new variable
called oldvar (not the same as mydata$oldvar) and sets it to "topic1" because a
single equa
> 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
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
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
Thanks for this, Bill
Your solution does just what I want. In fact, it qualifies as the
missing as.matrix() method
for n-way tables arranged with ftable(), or vcd::structable(), which
does provide an
as.matrix() method, but omits the names and dimnames.
Here it is, renamed and
using "_" as t
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
Do you just want to change how the rows and columns of ftable's output are
labelled? If so, the following may do what you want: it produces a matrix
with dimnames based on the row.vars and col.vars attributes of ftable's
output.
f <- function(ftable) {
makeDimNamesEl <- function(x) {
Hi,
May be this helps:
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 GG nc AA
ID4 _ _ _ _
ID5 CC GG CC AA
ID6 CC GG CC AA
ID7 CC GG CT AA
ID8 _ _ _ _
ID9 CT
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
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
Hi,
set.seed(125)
dat1<-data.frame(BIRTHPLACE=sample(c("AG","AI","AR","BE","ZH","USA","GER","ESP"),20,replace=TRUE),RES_STA=sample(LETTERS[c(1:3,24:25)],20,replace=TRUE))
dat1$VARNEW<-ifelse(dat1$RES_STA=="X" &
dat1$BIRTHPLACE%in%c("AG","AI","AR","BE","ZH"),"swiss","unknown")
A.K.
- Origi
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
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 everybody!
>
> I have a rather
I can't replicate your problem. I created a data set with "Male" and
"Female" since that is what you indicate, but your commands use "M" and "F"
which is different. When I use "Male" and "Female" the recoding is just as
expected, but you don't even need to do this. You probably already have a
facto
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
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
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
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]
>
>
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
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
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
##
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,{
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
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
Now I have :)
Thanx a lot!
2010/4/8 David Winsemius
>
> On Apr 8, 2010, at 8:13 AM, Vlatka Matkovic Puljic wrote:
>
> Dear,
>>
>> my variable is numerical indicating how many times smb done test
>> summary(Q12)
>> Min. 1st Qu. MedianMean 3rd Qu.Max.NA's
>> 0. 0. 0.
On Apr 8, 2010, at 8:13 AM, Vlatka Matkovic Puljic wrote:
Dear,
my variable is numerical indicating how many times smb done test
summary(Q12)
Min. 1st Qu. MedianMean 3rd Qu.Max.NA's
0. 0. 0. 0.7989 1. 30. 66.
I want to change this to categories--> 0=
Dear,
my variable is numerical indicating how many times smb done test
summary(Q12)
Min. 1st Qu. MedianMean 3rd Qu.Max.NA's
0. 0. 0. 0.7989 1. 30. 66.
I want to change this to categories--> 0=none testing; 1:30=done testing (NA
excluded)
John, *cut(Q
Dear Vlatka,
It's impossible to know what the problem is without knowing something about
your data, which you didn't tell us either in this message or your
subsequent one.
The recode command should work:
> (x <- c(rep(0, 5), sample(1:30, 5, replace=TRUE)))
[1] 0 0 0 0 0 17 27 19 19 2
> r
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
Dear Abraham,
If I follow correctly what you want to do, the following should do it:
> f <- factor(c(1, 1, 5, 5, 8, 8, 9, 9, 0, 0))
> f
[1] 1 1 5 5 8 8 9 9 0 0
Levels: 0 1 5 8 9
> recode(f, " '1'=3; '5'=1; '0'=2; else=NA ")
[1] 331122
Levels: 1 2 3
I think that your
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
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 variables wit
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
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"
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
Dear Agustin,
Perhaps
v1 <- c(1,1,1,2,3,4,1,10,3)
dput(as.numeric(ifelse(v1%in%c(1,2,3),paste(100,v1,sep=""),v1)))
HTH,
Jorge
On Fri, Jun 27, 2008 at 2:41 PM, Agustin Lobo <[EMAIL PROTECTED]> 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 d
Many, many thanks Erik! For anyone who is searching around looking for a
way to recode in R, here's the full code Erik provided:
var_list <- c("HEQUAL", "EWEALTH", "ERADEQ", "HREVDIS1", "EDISCRIM",
"HREVDIS2") ## my original list of variables
mdf <- data.frame(replicate(length(var_list), sample(
Got it, I did not know of the 'recode' function in car.
So you would like to recode those specific columns then? Once again, we
can do it without a loop, this time with the help of a function called
lapply, which applies a function to each item in a list in turn.
Try:
reverse_me_varnames <-
Erik,
Your example was just what I needed to generate the data -- many, many
thanks! The names() function was something I had not grasped fully. I now
have this and it works very nicely:
var_list <- c("HEQUAL", "EWEALTH", "ERADEQ", "HREVDIS1", "EDISCRIM",
"HREVDIS2")
mdf <- data.frame(replicate(
Many thanks --
You are right; I had rnorm() and sample() mixed up in my code. I'll work on
generating a normal ordinal sample next.
Cheers, Don
On Mon, May 19, 2008 at 4:07 PM, Erik Iverson <[EMAIL PROTECTED]>
wrote:
> Hello -
>
> Donald Braman wrote:
>
>> # I'm new to R and am trying to get th
Hello -
Donald Braman wrote:
# I'm new to R and am trying to get the hang of how it handles
# dataframes & loops. If anyone can help me with some simple tasks,
# I'd be much obliged.
# First, i'd like to generate some random data in a dataframe
# to efficiently illustrate what I'm up to.
# let'
Thanks for quick response! I have done. I have tried many configurations
of the various examples given there, but the examples are pretty short and
none explain how to loop through nonconsecutive variables in a data frame.
I've also read dozens of pages that come up when I google "data.frame rno
If you're serious, start by reading the docs, especially "An Introduction to
R." There are also other learning resources listed on CRAN.
-- Bert gunter
Genentech
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Donald Braman
Sent: Monday, May 19, 2008 12
Note that if you do use NA rather than 99 as others have suggested then
the A==4 term should use ifelse rather than multiplication since 0 *
NA = NA, not 0:
transform(Data, new =
(A == 1) * ((B == 1) - (B == 2)) + (A == 2) * ((B == 2) - (B ==1))
+ ifelse(A == 4, NA, 0))
In fact, although more
On 23/01/2008, at 2:02 PM, hadley wickham wrote:
> No one else mentioned this, but if those 99s represent missings, you
> should be using NA not a special numeric value.
Amen, bro. Using ``99'' to represent a missing value is
a heinous, if all too often inflicted, crime against
No one else mentioned this, but if those 99s represent missings, you
should be using NA not a special numeric value.
Hadley
On Jan 22, 2008 5:40 PM, Dimitri Liakhovitski <[EMAIL PROTECTED]> wrote:
> Thanks a lot, everyone!
> Dimitri
>
>
> On 1/22/08, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
Thanks a lot, everyone!
Dimitri
On 1/22/08, Gabor Grothendieck <[EMAIL PROTECTED]> wrote:
> Slight correction of the English:
>
> - if A is 1 then the first term equals the coefficient of (A == 1).
> That is the first term equals 1 if B==1 and equals -1 if B==2.
> If A does not equal 1 then the
Slight correction of the English:
- if A is 1 then the first term equals the coefficient of (A == 1).
That is the first term equals 1 if B==1 and equals -1 if B==2.
If A does not equal 1 then the first term is zero and can be ignored.
- terms 2 and 3 are interpreted analogously
- if A==3 (or o
-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Gabor Grothendieck
Sent: Tuesday, January 22, 2008 11:09 AM
To: Dimitri Liakhovitski
Cc: R-Help List
Subject: Re: [R] recoding one variable into another - but differently
fordifferent cases
You could create a l
You could create a lookup table or use recode in the car package.
Another possibility is to use a logical/arithmetic expression. The
following expression says that
- if A is 1 then use the first term equals the coefficient, namely 1
if B ==1 and -1 if B == 2.
Also, if A is not 1 then that term
Dimitri Liakhovitski wrote:
> Hello,
> I have 2 variables in my sample Data: Data$A and Data$B
> Variable Data$A can assume values: 1, 2, 3, and 4.
> Variable Data$B identifies my cases and can assume values: 1 and 2.
>
> I need to recode my variable Data$A into a new variable Data$new such that:
89 matches
Mail list logo