ifelse() often has problems constructing the right type of return value.
if you want to keep the data as a factor (with its existing levels)
use x[condition] <- value instead of ifelse(condition, value, x). E.g.,
> x <- factor(c("Large","Small","Small","XLarge"),
levels=c("Small","Med","Large"
Apologies - you're right. Missed it in the pdf.
K.
On Sun, Sep 28, 2014 at 10:22 AM, Bert Gunter wrote:
> Inline.
>
> Bert Gunter
> Genentech Nonclinical Biostatistics
> (650) 467-7374
>
> "Data is not information. Information is not knowledge. And knowledge
> is certainly not wisdom."
> Cliffo
Inline.
Bert Gunter
Genentech Nonclinical Biostatistics
(650) 467-7374
"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
Clifford Stoll
On Sun, Sep 28, 2014 at 6:38 AM, Kate Ignatius wrote:
> Strange that,
>
> I did put everything with as.charact
Strange that,
I did put everything with as.character but all I got was the same...
class of dbpmn[,2]) = factor
class of dbpmn[,21] = factor
class of dbpmn[,20] = data.frame
This has to be a problem ???
I can put reproducible output here but not sure if this going to of
help here. I think its
I believe you are in Circle 8.2.7 of
The R Inferno.
http://www.burns-stat.com/documents/books/the-r-inferno/
Pat
On 28/09/2014 05:49, Kate Ignatius wrote:
Quick question:
I am running the following code on some variables that are factors:
dbpmn$IID1new <- ifelse(as.character(dbpmn[,2]) ==
as
On Sun, 28 Sep 2014 12:49:41 AM Kate Ignatius wrote:
> Quick question:
>
> I am running the following code on some variables that are factors:
>
> dbpmn$IID1new <- ifelse(as.character(dbpmn[,2]) ==
> as.character(dbpmn[,(21)]), dbpmn[,20], '')
>
> Instead of returning some value it gives me this
Not reproducible, ball in your court. However, in the meantime, my suggestion
is to not do that. Convert to character before you alter the factor, then
convert back when you are done.
---
Jeff Newmiller
Quick question:
I am running the following code on some variables that are factors:
dbpmn$IID1new <- ifelse(as.character(dbpmn[,2]) ==
as.character(dbpmn[,(21)]), dbpmn[,20], '')
Instead of returning some value it gives me this:
c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1))
Playing around wi
Hi Adel,
If the problem is the spacing, then
library(stringr)
1*(long_df$country_name %in% str_trim(countrydiff))
# [1] 1 0 0 1 1 0 0 0 0 0
A.K.
Dear Arun
Thanks for your reply, it made me realize that the problem was
not in the code but in the levels() of the factors. Some countries had
som
Dear Arun
Thanks for your reply, it made me realize that the problem was not in the
code but in the levels() of the factors. Some countries had some extra
spacing which made the ifelse() function not work. So if I modify your code
(added space to countrydiff), it will then look something like thi
Hi,
Suggestion 1: read
http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example
and bookmark it for future reference.
Suggestion 2:
set.seed(123)
countrydiff <- letters[1:5]
long_df <- data.frame(country_name = sample(letters[1:8], 20, replace=TRUE))
long_df$povdat <
Dear list-members,
I have the following problem: I have a vector (countrydiff) with length 72
and another vector (long_df$country_name) which is about 12000 long.
Basically what I want to do is to if the factor level (or string name) in
long_df$country_name appears on the countrydiff, then long_d
Hi,
Please show a reproducible example.
countrydiff <- c("Albania", "Algeria", "Belarus", "Canada", "Germany")
long_df <- data.frame(country_name = c("Algeria", "Guyana", "Hungary",
"Algeria", "Canada", "Iran", "Iran", "Norway","Uruguay", "Zimbabwe") )
ifelse(long_df$country_name %in% countrydif
Hi,
You've got several things going on here.
On Mon, Jul 11, 2011 at 3:39 PM, fre wrote:
> Hello everyone,
>
> I have a (small) issue. I already googled a lot, so I decided to use ifelse
> instead of if (){} else{}
>
> All the elements seem to work seperately, but combined in the ifelse
> statem
Hello everyone,
I have a (small) issue. I already googled a lot, so I decided to use ifelse
instead of if (){} else{}
All the elements seem to work seperately, but combined in the ifelse
statement, it doesn't seem to work.
#The price function is a function which is normally distributed with only
Hi,
Not sure since I've never done it, but shouldn't it be NA instead of NULL?
Ivan
Le 9/17/2010 15:23, n.via...@libero.it a écrit :
> Dear list,
> I have a question I'm trying to use the following command in R, but it gives
> me an error message.The command is:
>
> data<-ddply(data,c("year","
Dear list,
I have a question I'm trying to use the following command in R, but it gives
me an error message.The command is:
data<-ddply(data,c("year","name"), transform, check1=ifelse(check1==1 &
check2==1, 1,NULL))
so in my data frame I already have the check1 variable, if the conditions
(che
that makes sense. thank you, guys!
--
View this message in context:
http://r.789695.n4.nabble.com/ifelse-statement-tp2281576p2281706.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@r-project.org mailing list
https://stat.ethz.c
On 2010-07-08, at 10:33 , Duncan Murdoch wrote:
> On 07/07/2010 7:32 PM, Gabor Grothendieck wrote:
>> On Wed, Jul 7, 2010 at 7:22 PM, Duncan Murdoch
>> wrote:
>>
>>> On 07/07/2010 5:58 PM, karena wrote:
>>>
Hi, I am a newbie of R, and playing with the "ifelse" statement.
I
On 07/07/2010 7:32 PM, Gabor Grothendieck wrote:
On Wed, Jul 7, 2010 at 7:22 PM, Duncan Murdoch wrote:
On 07/07/2010 5:58 PM, karena wrote:
Hi, I am a newbie of R, and playing with the "ifelse" statement.
I have the following codes:
## first,
for(i in 1:3) {
for(j in 2:4) {
cor.temp
On Wed, Jul 7, 2010 at 7:22 PM, Duncan Murdoch wrote:
> On 07/07/2010 5:58 PM, karena wrote:
>>
>> Hi, I am a newbie of R, and playing with the "ifelse" statement.
>>
>> I have the following codes:
>> ## first,
>>
>> for(i in 1:3) {
>> for(j in 2:4) {
>> cor.temp <- cor(iris.allnum[,i], iris.allnu
On 07/07/2010 5:58 PM, karena wrote:
Hi, I am a newbie of R, and playing with the "ifelse" statement.
I have the following codes:
## first,
for(i in 1:3) {
for(j in 2:4) {
cor.temp <- cor(iris.allnum[,i], iris.allnum[,j])
if(i==1 & j==2) corr.iris <- cor.temp
else corr.iris <- c(corr.iris, cor.
Hi, I am a newbie of R, and playing with the "ifelse" statement.
I have the following codes:
## first,
for(i in 1:3) {
for(j in 2:4) {
cor.temp <- cor(iris.allnum[,i], iris.allnum[,j])
if(i==1 & j==2) corr.iris <- cor.temp
else corr.iris <- c(corr.iris, cor.temp)
}
}
this code is working fine.
23 matches
Mail list logo