Hello,
You're right, sorry, I missed the parenthesis:
colordata$response <- (colordata$color == 'blue') + 0
Rui Barradas
Quoting Michael Artz :
> Fyi, This statement returned the following error
> 'Error in "Yes" + 0 : non-numeric argument to binary operator'
>
>
> On Thu, Apr 7, 2
Hi
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Michael
> Artz
> Sent: Friday, April 8, 2016 3:50 AM
> To: Hadley Wickham
> Cc: r-help@r-project.org
> Subject: Re: [R] simple question on data frames assignment
>
> Wh
ybe you shall use dput(yourdata) output together with desired result to help
us better understand your task.
Cheers
Petr
From: Michael Artz [mailto:michaelea...@gmail.com]
Sent: Thursday, April 7, 2016 4:17 PM
To: PIKAL Petr
Subject: Re: [R] simple question on data frames assignment
what about
Why am I better off with true and false?
On Thu, Apr 7, 2016 at 8:41 AM, Hadley Wickham wrote:
> == is also vectorised, and you're better off with TRUE and FALSE
> rather than 1 and 0, so I'd recommend:
>
> colordata$response <- colordata$color == 'blue'
>
> Hadley
>
> On Thu, Apr 7, 2016 at 6:5
Fyi, This statement returned the following error
'Error in "Yes" + 0 : non-numeric argument to binary operator'
On Thu, Apr 7, 2016 at 8:43 AM, wrote:
> Hello,
>
> Or even simpler, without ifelse,
>
> colordata$response <- colordata$color == 'blue' + 0
>
> Hope this helps,
>
> Rui Barradas
>
>
It all makes so much sense now
On Thu, Apr 7, 2016 at 10:04 AM, Jeff Newmiller
wrote:
> lapply(colordata2[ -1 ], f )
>
> When you put the parentheses on, you are calling the function yourself
> before lapply gets a chance. The error pops up because you are giving a
> vector of numbers (the answe
lapply(colordata2[ -1 ], f )
When you put the parentheses on, you are calling the function yourself before
lapply gets a chance. The error pops up because you are giving a vector of
numbers (the answer f gave you) to the second argument of lapply instead of a
function.
--
Sent from my phone.
If you are not using an anonymous function and say you had written the
function out
The below gives me the error > 'f(colordata2$color1)' is not a function,
character or symbol' But then how is the anonymous function working?
f <- function(col){
ifelse(col == 'blue', 1, 0)
}
responses <- lapp
Hello,
Or even simpler, without ifelse,
colordata$response <- colordata$color == 'blue' + 0
Hope this helps,
Rui Barradas
Citando David Barron :
> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>
> David
>
> On 7 Ap
== is also vectorised, and you're better off with TRUE and FALSE
rather than 1 and 0, so I'd recommend:
colordata$response <- colordata$color == 'blue'
Hadley
On Thu, Apr 7, 2016 at 6:52 AM, David Barron wrote:
> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <-
Lapply is not a vectorized function. It is compact to read, but it would not be
worth using for this calculation.
However, if your data frame had multiple color columns in your data frame that
you wanted to make responses for then you might want to use lapply as a more
compact version of a for
Hi
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Michael
> Artz
> Sent: Thursday, April 7, 2016 1:57 PM
> To: David Barron
> Cc: r-help@r-project.org
> Subject: Re: [R] simple question on data frames assignment
>
> Th
Thaks so much! And how would you incorporate lapply() here?
On Thu, Apr 7, 2016 at 6:52 AM, David Barron wrote:
> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>
> David
>
> On 7 April 2016 at 12:41, Michael Artz wrot
ifelse is vectorised, so just use that without the loop.
colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
David
On 7 April 2016 at 12:41, Michael Artz wrote:
> Hi I'm not sure how to ask this, but its a very easy question to answer for
> an R person.
>
> What is an easy way to che
Hi I'm not sure how to ask this, but its a very easy question to answer for
an R person.
What is an easy way to check for a column value and then assigne a new
column a value based on that old column value?
For example, Im doing
colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red",
15 matches
Mail list logo