Displaying 20 results from an estimated 9000 matches similar to: "How to recode variables using base R"
2010 Apr 07
2
recoding variables-recode not working
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'))
cat(Q12, "0=0;1-33=1")
What should
2012 Aug 20
7
What makes R different from other programming languages?
My intention is to give a presentation about R programming language
for software developers. I would like to ask, what are the things that
make R different from other programming languages? What are the
specific cases where Java/C#/Python developer might say "Wow, that was
neat!"? What are the things that are easy in R, but very difficult in
other programming languages (like Java)?
2006 Jul 02
2
how to recode in my dataset?
Dear Rusers,
My question is about "recode variables". First, i'd like to say
something about the idea of recoding:
My dataset have three variables:type,soiltem and airtem,which means
grass type, soil temperature and air temperature. As we all known, the
change of air temperature is greater than soil temperature,so the
values in those two different temperaturemay represent different
2008 Mar 27
1
Recode factors
I know this comes up, but I didn't see my exact issue in the archives. I
have variables in a dataframe that need to be recoded. Here is what I'm
dealing with
I have a factor called aa
> class(aa)
[1] "factor"
> table(aa)
aa
* 0 1 2 3 A B C D L N T
0 0 1908 725 2089 0 0 67 0 0 2 1 6
I need to recode
2009 Apr 01
4
Recode of text variables
Hi all
I am trying to do a simple recode which I am stumbling on. I figure
there must be any easy way but haven't come across it.
Given data of A","B","C","D","E","A" it would be nice to recode this
into say three categories ie A and B becomes "Treat1", C becomes "Treat
2" and E becomes "Treat 3".
I tried
2010 Jan 28
1
Recoding Variables in R
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?
1. Favor
5. Oppose
8. DK
9. NA; RF
0. Haven't thought much about this
I am trying to
2010 Nov 17
2
Regexp question
I have a vector like this:
a <- c("thisIsName", "thisIsAlsoName", "andThisName")
How to break this into pieces and produce a vector with unique parts:
this
Is
Name
Also
and
This
-J
2011 Aug 12
2
recode Variable in dependence of values of two other variables
Hi,
as an R-beginner, I have a recoding problem and hope you can help me:
I am working on a SPSS dataset, which I loaded into R (load("C:/...)
I have 2 existing Variables: "ID" and "X" ,
and one variable to be computed: meanX.dependID (=mean of X for all rows
in which ID has the same value)
ID = subject ID. Since it is a longitudinal dataset, there are repeated
2001 Mar 27
4
recode vector values to NA
Greetings,
I'm in the painful process of migrating from SAS to R. In the process I've
discovered that there are some basic things that I am getting hung up on. The
most basic is the simple recoding of variables. Suppose I create a vector
x <- rnorm(10000)
and I want to recode all values of x > 1.5 to NA. How would I do that in R?
TIA
Cheers,
Patrick
2013 May 07
2
recode categorial vars into binary data
Dear R-List,
I would like to recode categorial variables into binary data, so that all values above median are coded 1 and all values below 0, separating each var into two equally large groups (e.g. good performers = 0 vs. bad performers =1).
I have not succeeded so far in finding a nice solution to do that in R. I thought there might be a better way than ordering each column and recoding the
2013 May 07
2
recode categorial vars into binary data
Dear R-List,
I would like to recode categorial variables into binary data, so that all values above median are coded 1 and all values below 0, separating each var into two equally large groups (e.g. good performers = 0 vs. bad performers =1).
I have not succeeded so far in finding a nice solution to do that in R. I thought there might be a better way than ordering each column and recoding the
2009 Jun 12
2
Sweave recode(car) and Lyx, compiling but not executing on Mac
I am just beginning to use Sweave with Lyx on a Mac (R2.8.1). I have
12 chunks of Sweave code that work fine, but this piece:
<<>>=
library(car)
2005 Jul 28
1
Unexpected behavior in recode{car}
Thanks to the R creators for such a great statistical system. Thanks to
the R help list, I have (finally) gotten far enough in R to have a
question I hope to be worth posting.
I'm using the recode function from John Fox's car package and have
encountered some unexpected behavior.
Consider the following example:
## Begin cut-and-paste example
require( car )
set.seed(12345)
nn <-
2011 May 04
3
Regexp question
I have a string like this
st <- "SELECT COUNT(empid), COUNT(mgrid), COUNT(empname),
COUNT(salary), FROM Employees"
How can I remove the last comma before the FROM statement?
-J
2009 Sep 30
3
AsciiDoc and R
I would like to learn AsciiDoc. Is there any good examples how to use
AsciiDoc with R? I know that there is packages called ascii to do
this, but it would be nice to see some examples how AsciiDoc works
with R. Is there an AsciiDoc distribution for Max OS X?
-Johannes
2010 Nov 08
7
How to rbind list of vectors with unequal vector lengths?
Hi,
How to rbind these vectors from a list?:
> l <- list(a = c(1, 2), b = c(1, 2, 3))
> l
$a
[1] 1 2
$b
[1] 1 2 3
> do.call(rbind, l)
[,1] [,2] [,3]
a 1 2 1
b 1 2 3
Warning message:
In function (..., deparse.level = 1) :
number of columns of result is not a multiple of vector length (arg 1)
>
-J
2008 May 28
1
manipulating multiply imputed data sets
Hi folks,
I have five imputed data sets and would like to apply the same
recoding routines to each. I could do this sort of thing pretty
easily in Stata using MIM, but I've decided to go cold turkey on other
stats packages as a incentive for learning more about R. Most of the
recoding is for nominal variables, like race, religion, urbanicity,
and the like. So, for example, to recode race
2006 Jun 23
1
numeric variables converted to character when recoding missing values
Dear R helpers,
I have a data frame where missing values for numeric variables are coded as
999. I want to recode those as NAs. The following only partially succeeds
because numeric variables are converted to character in the process:
df <- data.frame(a=c(999,1,999,2), b=LETTERS[1:4])
is.na(df[2,1]) <- TRUE
df
a b
1 999 A
2 NA B
3 999 C
4 2 D
is.numeric(df$a)
[1] TRUE
2003 Dec 06
1
recode{car} does not work as expected?
Hi to all,
I am having a problem when using recode from the car package. I have
a variable that is char and when I use recode to create a new
variable that is supposed to be numeric I get a factor variable. Here
is the code I am using:
> FCI$PRE1 <- recode (PRE1RES, " c('C', 'c')=1 ; else = 0 ;
as.factor.result=FALSE ")
So, if I understand correctly the recode
2010 Jun 15
1
Problem with the recode function
Hello,
I am using the recode() function in Rcmdr and the result is not what I
expect so I am almost sure I did something wrong but what...
> test <- data.frame(x=1:10)
> library(car)
> recode(test$x,'1:5=0 ; else=1', as.factor.result=TRUE)
[1] 0 0 0 0 0 1 1 1 1 1
Levels: 0 1
BUT
> library(Rcmdr) # recode from the car package is now masked
Now I recode test$x