Displaying 13 results from an estimated 13 matches for "colordata".
2016 Apr 07
4
simple question on data frames assignment
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",
"green", "blue", "orange"))
for (i in 1:nrow(colordata)){
colordata$response[i] <- ifelse(colordata[i,"color"] == "blue", 1, 0)
}
which works, but I don't...
2016 Apr 07
0
simple question on data frames assignment
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 <michaeleartz at gmail.com> 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 check for a...
2016 Apr 07
2
simple question on data frames assignment
Hello,
Or even simpler, without ifelse,
colordata$response <- colordata$color == 'blue' + 0
Hope this helps,
Rui Barradas
?
Citando David Barron <dnbarron at gmail.com>:
> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>
> Dav...
2016 Apr 08
0
simple question on data frames assignment
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, <ruipbarradas at sapo.pt> wrote:
> Hello,
>
> Or even simpler, without ifelse,
>
> colordata$response <- colordata$color == 'blue' + 0
>
> Hope this helps,
>
> Rui Barradas
>
>
> Citando David Barron <dnbarron at gmail.com>:
>
> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <- ifelse(colordata$color == &...
2016 Apr 07
2
simple question on data frames assignment
== 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 <dnbarron at gmail.com> wrote:
> ifelse is vectorised, so just use that without the loop.
>
> colordata$response <- ifelse(colordata$color == 'blue', 1, 0)
>
> Davi...
2016 Apr 07
4
simple question on data frames assignment
Thaks so much! And how would you incorporate lapply() here?
On Thu, Apr 7, 2016 at 6:52 AM, David Barron <dnbarron at gmail.com> 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 <michaeleartz at gmail.com> wrote:
>
>> Hi I'm not sure how to ask this, but its a very easy question to answer
>> for
>> an R person.
>&...
2016 Apr 08
0
simple question on data frames assignment
Why am I better off with true and false?
On Thu, Apr 7, 2016 at 8:41 AM, Hadley Wickham <h.wickham at gmail.com> 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:52 AM, David Barron <dnbarron at gmail.com> wrote:
> > ifelse is vectorised, so just use that without the loop.
> >
> > colordata$response <- ifelse(colordata$color == ...
2016 Apr 07
2
simple question on data frames assignment
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 <- lapply(colordata2[ -1 ], f(colordata2$color1) )
'f(colordata2$color1)' is not a function, character or...
2016 Apr 07
0
simple question on data frames assignment
...ction. 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 loop to repeat this operation.
colordata2 <- data.frame(id = c(1,2,3,4,5), color1 = c("blue", "red",
"green", "blue", "orange"), color2 = c("orange", "green",
"blue", "red", "red"))
responses <- lapply( colordata2[ -1 ], function(col)...
2016 Apr 07
0
simple question on data frames assignment
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. Please excuse my bre...
2016 Apr 08
0
simple question on data frames assignment
...end some time with R tutorials.
1. lapply or sapply is basically hidden cycle
2. function shall return something, yours does not
So if you want some binary outcome from a vector you can use e.g.
f <- function(vector, token) {
response <- vector==token
response
}
So with your colordata
> colordata
id color
1 1 blue
2 2 red
3 3 green
4 4 blue
5 5 orange
You can get this
> colordata$result <- f(colordata$color, "blue")
> colordata
id color result
1 1 blue TRUE
2 2 red FALSE
3 3 green FALSE
4 4 blue TRUE
5 5 orange FALS...
2010 Mar 24
3
help in matlab - r code
...line 2),
# converts the image to grayscale data (line 3), and calculates the
autocorrelation curve
# for offset distances of one pixel to 99 pixels (lines 7–10). This code can
be used to
# perform steps (4) and (6) listed above in the Summary of Steps to
Calculate Grain
# Size of Natural Sediment.
ColorData = imread(‘ImageName.jpg’); x <- read.jpeg("sed2.jpg")# opens the
image
imshow(ColorData); plot(x) # plot image
data = double(rgb2gray(ColorData)); x=rgb2grey(x) # transform in grayscale,
the image
; # example of a similar data matrix: data =
double(0.54878431372549,0.468,0.553411764705...
2012 Mar 02
1
3d surface plot (ideally using rgl package)?
...be grateful for anybody who might help to produce the following
plot (the code for matlab is below) using the "rgl" package of R?
[t,r] = meshgrid(linspace(0,2*pi,361),linspace(-4,4,101));
[x,y] = pol2cart(t,r);
P = peaks(x,y);
figure('color','white');
polarplot3d(P,'colordata',gradient(P));
view([-18 72]);
You may see the code and plot output at:
https://plus.google.com/u/0/109789409461372488563/posts/YfcrsMhkjyf
Many Thanks
A.
[[alternative HTML version deleted]]