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
> I want to do a boxcox transformation, but I got this:
> Error: could not find function "boxcox"
>
> What can I do?
Well, the recommended 'homework' in the posting guide would be a start.
i) ??boxcox, if you have any packages installed that include something with
that functionality.
ii) RSite
Hi,
Maybe the following link helps.
http://r.789695.n4.nabble.com/box-cox-td4363944.html
--
View this message in context:
http://r.789695.n4.nabble.com/SIMPLE-question-tp4703176p4703180.html
Sent from the R help mailing list archive at Nabble.com.
Hello,
Try the following.
install.packages("sos") #if not yet
Then,
library(sos)
findFn("boxcox")
There are several hits, maybe you could start with package car
Hope this helps,
Rui Barradas
Em 12-02-2015 16:19, CHIRIBOGA Xavier escreveu:
Hi everybody!
I want to do a boxcox transform
Hi,
rock[2,] is a data frame and you should not use sum() on a data frame, first
google hit for the error message gives
http://stackoverflow.com/questions/19697498/r-beginner-argument-is-not-numeric-or-logical-returning-na
Otherwise I think you should use
?rowSums and ?rowMeans if you have num
Use mapply instead
On Fri, Nov 16, 2012 at 5:01 PM, billycorg wrote:
> Hi R Users.
>
> I have a simple question on a loop.
>
> The following loop works fine:
>
> r_t=list()
> for(i in 1:500)
> {
> r_t[[i]]=h_t_half[[i]]%*%matrix(*z_t_m*[i,])
> }
>
> But indeed I need also that *z_t_m* varies. Let
On Fri, Sep 28, 2012 at 11:15 AM, Bhupendrasinh Thakre
wrote:
> Thanks a ton Berend. That worked like a charm..
> R comes with thousands of Sweet Surprises everyday
-- Not for those who read the docs. :-o
-- Bert
>
>
> Bhupendrasinh Thakre
>
>
>
>
> On Sep 28, 2012, at 12:00 PM, Berend
Thanks a ton Berend. That worked like a charm..
R comes with thousands of Sweet Surprises everyday
Bhupendrasinh Thakre
On Sep 28, 2012, at 12:00 PM, Berend Hasselman wrote:
>
> On 28-09-2012, at 18:40, Bhupendrasinh Thakre wrote:
>
>> Hi Everyone,
>>
>> Sorry for coming back ag
On 28-09-2012, at 18:40, Bhupendrasinh Thakre wrote:
> Hi Everyone,
>
> Sorry for coming back again with a new problem.
> Editing question, session info and data so you don't have to scroll till
> the end of page.
>
> *Situation :*
>
> I have a data frame and it's name is df. Now I want to ad
Hi Everyone,
Sorry for coming back again with a new problem.
Editing question, session info and data so you don't have to scroll till
the end of page.
*Situation :*
I have a data frame and it's name is df. Now I want to add Time Stamp to
the end of *"name" of "data Frame" i.e. "df_system_time"*.
Hi Everyone,
Sorry for coming back again with a new problem.
Editing question, session info and data so you don't have to scroll till
the end of page.
*Situation :*
I have a data frame and it's name is df. Now I want to add Time Stamp to
the end of *"name" of "data Frame" i.e. "df_system_time"*.
Many thanks Dr. Winsemius , Kimmo and Pascal
All of them are working and really beautiful...
Best Regards,
Bhupendrasinh Thakre
*Disclaimer :*
The information contained in this communication is confidential and may be
legally privileged. It is intended solely for the use of the individual
On Sep 27, 2012, at 11:13 PM, Bhupendrasinh Thakre wrote:
>
> Hi Everyone,
>
> I am trying a very simple task to append the Timestamp with a variable name
> so something like
> a_2012_09_27_00_12_30 <- rnorm(1,2,1).
If you want to assign a value to a character-name you need to use ... `assig
Hello,
Try the following:
b <- unclass(Sys.time())
eval(parse(text=paste("c_",b," <- rnorm(1,2,1)",sep="")))
ls()
Regards,
Pascal
Le 28/09/2012 15:13, Bhupendrasinh Thakre a écrit :
Hi Everyone,
I am trying a very simple task to append the Timestamp with a variable name so
something like
Hi!
28.09.2012 09:13, Bhupendrasinh Thakre wrote:
Statement I tried :
b <- unclass(Sys.time())
b = 1348812597
c_b <- rnorm(1,2,1)
Do you mean this:
--- code ---
> df<-data.frame("x"=0,"y"=0)
> colnames(df)
[1] "x" "y"
> colnames(df)[2]<-paste("b",unclass(Sys.time()),sep="_")
> colnames(df)
Hello,
In the help page for ?hclust you will see the return values. It has an
element order, "a vector giving the permutation of the original
observations suitable for plotting".
From the first example on that page:
hc <- hclust(dist(USArrests), "ave")
plot(hc)
ix <- hc$order
rownames(USArre
Check the return values for hclust using ?hclust (particularly the
value order):
> set.seed(42)
> x <- matrix(rnorm(100), nrow=25)
> outp <- hclust(dist(x))
> plot(outp)
> outp$order
[1] 9 6 16 1 7 24 25 3 14 11 12 20 18 19 23 4 10 5 17 13 22 2
15 8 21
You could use this to reorder the d
On Wed, Sep 26, 2012 at 3:11 PM, RCar wrote:
> All,
> Relatively new R user so this is probably an easy question to answer.
> I am able to generate a cluster for my dataset using hclust() then ploting
> the data with plot().
> This results in an image with a dendrogram with my sample names along t
On Fri, Aug 10, 2012 at 9:16 AM, S Ellison wrote:
>> > R in general tries hard to prohibit this behavior (i.e., including an
>> > interaction but not the main effect). When removing a main effect and
>> > leaving the interaction, the number of parameters is not reduced by
>> > one (as would be ex
Sheesh! Yes.
... and in the case where B is a factor with k levels and x is
continuous, the model ~B:x yields k+1 parameters, which in default
contrasts would be a constant term, x, and k-1 interactions between x
and the corresponding k-1 "contrasts"(which they aren't really) for B.
~B*x would add
> > R in general tries hard to prohibit this behavior (i.e., including an
> > interaction but not the main effect). When removing a main effect and
> > leaving the interaction, the number of parameters is not reduced by
> > one (as would be expected) but stays the same, at least
> > when using
On Aug 10, 2012, at 8:09 AM, Joshua Wiley wrote:
On Fri, Aug 10, 2012 at 7:39 AM, Henrik Singmann
wrote:
Dear Michael and list,
R in general tries hard to prohibit this behavior (i.e., including an
interaction but not the main effect). When removing a main effect and
leaving the interaction,
On Fri, Aug 10, 2012 at 7:39 AM, Henrik Singmann
wrote:
> Dear Michael and list,
>
> R in general tries hard to prohibit this behavior (i.e., including an
> interaction but not the main effect). When removing a main effect and
> leaving the interaction, the number of parameters is not reduced by o
Dear Michael and list,
R in general tries hard to prohibit this behavior (i.e., including an
interaction but not the main effect). When removing a main effect and leaving
the interaction, the number of parameters is not reduced by one (as would be
expected) but stays the same, at least when us
On Fri, Aug 10, 2012 at 7:36 AM, ONKELINX, Thierry
wrote:
> Dear Johan,
>
> Why should it be complicated? You have a very simple model, thus a very
> simple formula. Isn't that great?
>
> Your formula matches the model. Though Trust~Culture + Structure *
> Speed_of_Integration is another option.
Dear Johan,
Why should it be complicated? You have a very simple model, thus a very simple
formula. Isn't that great?
Your formula matches the model. Though Trust~Culture + Structure *
Speed_of_Integration is another option. The model fit is the same, the only
difference is the parameterizatio
HI,
Try this:
a <- data.frame( col1 = c(1,2,3,3,4))
a<-within(a, duplicate<-c(0,ifelse(diff(a$col1)==0,1,0)))
a
col1 duplicate
1 1 0
2 2 0
3 3 0
4 3 1
5 4 0
A.K.
- Original Message -
From: Jeff
To: r-help@r-project.org
Cc:
S
duplicate <- c(0, diff(a[,"col1"]) == 0)
Peter Ehlers
On 2012-07-25 13:05, Jeff wrote:
I'm trying to find duplicate values in a column of a data frame. For
example, dataframe (a) below has two 3's. I would like to mark each value of
each row as either not being a duplicate of th
Sorry...
?duplicated
-- Bert
On Wed, Jul 25, 2012 at 1:28 PM, Bert Gunter wrote:
> ummm...
> ?duplicates
>
> -- Bert
>
> On Wed, Jul 25, 2012 at 1:22 PM, David L Carlson wrote:
>> duplicate <- ifelse(c(0, a$col[-length(a$col)])==c(a$col), 1, 0)
>>
>>
ummm...
?duplicates
-- Bert
On Wed, Jul 25, 2012 at 1:22 PM, David L Carlson wrote:
> duplicate <- ifelse(c(0, a$col[-length(a$col)])==c(a$col), 1, 0)
>
> --
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Stati
Minor correction:
duplicate <- ifelse(c(0, a$col[-length(a$col)])==a$col, 1, 0)
---
David
> -Original Message-
> From: David L Carlson [mailto:dcarl...@tamu.edu]
> Sent: Wednesday, July 25, 2012 3:23 PM
> To: 'Jeff'; 'r-help@r-project.org'
&g
duplicate <- ifelse(c(0, a$col[-length(a$col)])==c(a$col), 1, 0)
--
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help
Hello,
Try the following.
dd <- read.table(text="
chromlength
1 chr1 249250621
2 chr2 243199373
[... etc ...]
22 chr19 59128983
23 chr22 51304566
24 chr21 48129895
", header=TRUE)
str(dd)
dd$chrom <- as.character(dd$chrom)
dd$chrom <- sub("chr", "", dd$chrom)
# This 'chrom' is
??
ggplot did not reorder the columns -- it just plotted them in the order of
the levels of factor(chrom), which is exactly what you wanted afaics. There
is no need to reorder to do what you want.
Comment: ?dput to put reproducible data into an email that people can
conveniently copy and paste int
On May 15, 2012, at 8:42 PM, lapertem4 wrote:
x <- 3
y <- 4
max(x,y)
4
how can i get the greater variable name
y
Option one:
> test <- function(x,y) { c("x","y")[which.max(c(x,y))]}
> test(3,4)
[1] "y"
> test(4,3)
[1] "x"
Option two:
> test <- function(x,y) { xn <- depar
Yes! Thanks. It was just the "NA" value instead of the "as.null" that does
the trick. Correct code for the original piecewise I stated (for those who
might be looking later) is:
f <- function(x){
ifelse((-1 < x & x < 1),x^2,ifelse((2http://r.789695.n4.nabble.com/Simple-questio
Does
f <- function(x){
ifelse((-1 < x & x < 1) | (2 < x & x < 3),x^2,NA)
}
plot(f,xlim=c(-3,5))
give you what you want?
cheers,
Rolf Turner
On 26/03/12 11:08, chad.mills wrote:
I am a novice R user.
I would like to be able to graph some simple
Tried this, it does not seem to work.
It is really simple what I am trying to do. I have a pre-specified best-fit
line, and wish to run some diagnostic tests for goodness of fit.
I will play around with the predict function, thanks a lot David!
--
View this message in context:
http://r.78969
On Oct 12, 2011, at 2:25 PM, BvZ wrote:
I have hunted around but cannot find the command which allows me to
specify
parameters of a model.
For example,
model.m1 <- nls(y ~ alpha * x1/(beta + x1), data = data, start =
list(beta =
20, alpha = 120), trace = TRUE)
This will estimate the par
Thank you for the answer and sorry about the bad post i'll remember that
in the future.
By the way, the line code i used to read the data was
inv <- read.csv("data.csv", header=TRUE, sep=";")
I tried before to use the bg, but for some reason it wasn't working out for
me.
But now i got it.
Th
On Apr 20, 2011, at 8:45 AM, murilofm wrote:
The link to the csv file is
http://www.filedropper.com/data_5
I use the "d" variable to create the radius:
radius <- sqrt( inv$d/ pi )
and i tried
symbols(inv$a, inv$b, circles=radius, inches=0.35, fg="white",
bg="red", xlab="aa", ylab="bb",
The link to the csv file is
http://www.filedropper.com/data_5
I use the "d" variable to create the radius:
radius <- sqrt( inv$d/ pi )
and i tried
symbols(inv$a, inv$b, circles=radius, inches=0.35, fg="white",
bg="red", xlab="aa", ylab="bb",
col=c("blue","red")[inv$c+1])
Thanks for the
David Winsemius comcast.net> writes:
>
>
> On Apr 19, 2011, at 10:51 PM, murilofm wrote:
>
> > Thanks for the answer; I see that col=c("blue","red")[inv$c+1]
> > creates a
> > vector of "red" and "blue" associated with the binnary c.
> > But still I got everything red.
>
> If you want teste
On Apr 19, 2011, at 10:51 PM, murilofm wrote:
Thanks for the answer; I see that col=c("blue","red")[inv$c+1]
creates a
vector of "red" and "blue" associated with the binnary c.
But still I got everything red.
If you want tested solution, submit test data.
--
View this message in context:
Thanks for the answer; I see that col=c("blue","red")[inv$c+1] creates a
vector of "red" and "blue" associated with the binnary c.
But still I got everything red.
--
View this message in context:
http://r.789695.n4.nabble.com/Simple-question-about-symbols-tp3461676p3462013.html
Sent from the R he
murilofm gmail.com> writes:
>
> I'm new to R and i'm having some trouble with a bubble chart.
> Basically I have 3 series (a,b,c), but the third one is a binnary variable
> (assumes only 0 or 1 to the entire data).
> How can I use these binnary information to make 2 different colours in a
> bubb
Seconded.
Peter Ehlers
On 2011-04-19 14:11, Marc Schwartz wrote:
On Apr 19, 2011, at 4:08 PM, Rolf Turner wrote:
On 20/04/11 07:19, Steven Wolf wrote:
[...snip...]
It sounds to me like you don't understand lists. If you are going to use
R you really should understand them. They are a w
On Apr 19, 2011, at 21:56 , David Winsemius wrote:
>
> On Apr 19, 2011, at 3:19 PM, Steven Wolf wrote:
>
>> I am trying to convert a string to a vector, and I'm stuck!
>>
>>
>>
>> Suppose you have a string of numbers (string) that you want to convert to a
>> vector (vec). I am able to split
On Apr 19, 2011, at 4:08 PM, Rolf Turner wrote:
> On 20/04/11 07:19, Steven Wolf wrote:
>> I am trying to convert a string to a vector, and I'm stuck!
>>
>>
>>
>> Suppose you have a string of numbers (string) that you want to convert to a
>> vector (vec). I am able to split the string turning
On 20/04/11 07:19, Steven Wolf wrote:
I am trying to convert a string to a vector, and I'm stuck!
Suppose you have a string of numbers (string) that you want to convert to a
vector (vec). I am able to split the string turning it into a list by using
strsplit, but this makes a list, which I ca
On Apr 19, 2011, at 3:19 PM, Steven Wolf wrote:
I am trying to convert a string to a vector, and I'm stuck!
Suppose you have a string of numbers (string) that you want to
convert to a
vector (vec). I am able to split the string turning it into a list
by using
strsplit, but this makes a
Here are two options that might work for you given the little bit you've said:
## If its the same parameter all 30 times
## say, for example, base = 4.5 to log
for(i in 1:30) {
print(log(1:10, base = 4.5))
}
## if they are different parameters, you could try
lapply(X = c(1.3, 3, 2.2, 4, 5), FUN
Isn't it what do.call() does?
Ivan
Le 12/1/2010 16:39, Lamke a écrit :
Thank you so much Joshua. That's exactly what I am looking for.
What I wanted to do is to pass a parameter to a function and I have to run
the functions 30 times. Instead of typing them all out, I created a long
string of
Thank you so much Joshua. That's exactly what I am looking for.
What I wanted to do is to pass a parameter to a function and I have to run
the functions 30 times. Instead of typing them all out, I created a long
string of "f(a);f(b);f(c) ..." using paste() and use eval and parse to
evaluative t
Hi Kel,
Try this:
eval(parse(text = a))
x
Many times (though certainly not all), it may be easier/cleaner to
rethink what you are doing (the step before you get a <- "x <- 2^2")
to see if there is a simpler way.
Cheers,
Josh
On Tue, Nov 30, 2010 at 2:24 PM, Lamke wrote:
>
> Hi group,
>
> I d
On Fri, Sep 17, 2010 at 7:54 AM, C.H. wrote:
> Dear R users,
>
> I have a very simple question and I've tried to search for the answer.
> (But failed.)
>
> there should be a function (func) that work like
>
>> abc <- c(1,2,3,4)
>> func(abc)
> "abc"
>
> I would like to know the name of that functio
On Sep 17, 2010, at 2:54 AM, C.H. wrote:
Dear R users,
I have a very simple question and I've tried to search for the answer.
(But failed.)
there should be a function (func) that work like
abc <- c(1,2,3,4)
func(abc)
"abc"
> func <- function(xyz) deparse(substitute(xyz))
> func(abc)
[1]
subset(miceTrainSample, select = -plD50)
On Fri, Jul 16, 2010 at 11:22 AM, Addi Wei wrote:
>
> names(miceTrainSample)
> [1] "b_double" "KierA2" "KierFlex" "Q_VSA_POS" "pID50"
>
> In the above code, how do I delete "pID50" column to store the resulting
> object without indicating column "5".
Anyway, I have often wished that something like
new.mt.sample <- miceTrainSample[, -"pID50"]
would return miceTrainSample without the pID50 column. Here are three
alternative ways to do it.
# Method 1: Assign NULL to the column
new.mt.sample <- miceTrainsSample
new.mt.sample$pID50 <- NULL
# Me
Hi Addi,
On Fri, Jul 16, 2010 at 3:22 PM, Addi Wei wrote:
>
> names(miceTrainSample)
> [1] "b_double" "KierA2" "KierFlex" "Q_VSA_POS" "pID50"
>
> In the above code, how do I delete "pID50" column to store the resulting
> object without indicating column "5". The code below does the trick, b
On Thu, 2010-05-13 at 17:31 -0400, Carl Witthoft wrote:
> It's very simple to write a "binit()" function. If all you want to do
> is e.g., bin 107 values into sums of 10 at a time, then write a loop
> that sums x[10*i:11*i-1] (not tested and not syntactically correct).
>
> The one I wrote for
On 05/14/2010 07:35 PM, kMan wrote:
Wow! This definitely contributed to my evening.
If you could indulge, I would like some clarification on this matter of
binning and distortion, particularly wrt time series (perhaps related to
long-memory processes?). I had thought binning was standard practic
Wow! This definitely contributed to my evening.
If you could indulge, I would like some clarification on this matter of
binning and distortion, particularly wrt time series (perhaps related to
long-memory processes?). I had thought binning was standard practice in
spectral analysis and ANPOW.
..
I second it! Made me lol :)
Dennis
On Thu, May 13, 2010 at 3:03 PM, Rolf Turner wrote:
>
> On 14/05/2010, at 9:54 AM, Frank E Harrell Jr wrote:
>
>
>
> > Binning is seldom needed and usually distorts. It is
> > the statistical equivalent of a former governor from Alaska.
>
>
>
On 14/05/2010, at 9:54 AM, Frank E Harrell Jr wrote:
> Binning is seldom needed and usually distorts. It is
> the statistical equivalent of a former governor from Alaska.
I nominate this for a fortune.
cheers,
Rolf Turner
Cc: r-help@r-project.org
Subject: Re: [R] Simple question on binning data
There would be several people who could help if you gave us a minimal,
reproducible example like the posting guide asks for.
If you have a vector of continuous data, and need to create a
categorical variable (in R, a factor)
It's very simple to write a "binit()" function. If all you want to do
is e.g., bin 107 values into sums of 10 at a time, then write a loop
that sums x[10*i:11*i-1] (not tested and not syntactically correct).
The one I wrote for myself discards any partial bin (101-107 in my
example) and leav
lto:r-help-boun...@r-project.org] On
Behalf Of Erik Iverson
Sent: Thursday, May 13, 2010 1:51 PM
To: george5000
Cc: r-help@r-project.org
Subject: Re: [R] Simple question on binning data
There would be several people who could help if you gave us a minimal,
reproducible example like the posting guid
There would be several people who could help if you gave us a minimal,
reproducible example like the posting guide asks for.
If you have a vector of continuous data, and need to create a
categorical variable (in R, a factor) from that continuous variable,
then ?cut can help you.
george5000
Or use this handy-dandy function:
smode<-function(x){
xtab<-table(x)
modes<-xtab[max(xtab)==xtab]
mag<-as.numeric(modes[1]) #in case mult. modes, this is safer
themodes<-names(modes)
mout<-list(themodes=themodes,modeval=mag)
return(mout)
}
Gabriele -
How about this:
> data<-c("A","A","A","B","B","C","D")
> data
[1] "A" "A" "A" "B" "B" "C" "D"
> table(data)
data
A B C D
3 2 1 1
Thanks,
Lee
". . . people who focus only on 'what is' will create more of 'what is.'
People who focus mostly on 'what could be' will begin to create 'wh
On Apr 22, 2010, at 1:36 PM, Zoppoli, Gabriele (NIH/NCI) [G] wrote:
Hi
how can I find, in a vector of characters, which is the most
frequent one?
> a <- sample(letters[1:10], 100, replace=TRUE)
> table(a)
a
a b c d e f g h i j
10 7 7 13 7 12 1 14 15 14
> max(table(a))
[1] 15
Hi Gabriele,
This is one way but I'm sure that there is an optimal way of doing so...
x <- c("A","B","C","C","C","C","C","B","B")
name <- unique(x) # get unique characters
freq <- c()
for (a in 1:length(name)){
freq[a] <- sum(x==name[a])}# get frequency
out <- cbind(name,freq)
Hello,
What about
test <- c(rep(c("A","C","G","T"), 20),"C")
table(test)
I am not sure that is an apt representation of the data and problem
you are trying to solve. It also occurred to me that each character
may not be its own element in the vector. If that is so, you would
need to do somethi
If one of your variable is discrete,such as 1/0, the logistic regression is
better.Try the glm() function.
--
View this message in context:
http://n4.nabble.com/simple-question-about-contrasts-lm-and-factors-tp1835964p1837091.html
Sent from the R help mailing list archive at Nabble.com.
___
David.Epstein wrote:
>
> I have a data frame with two variables that are factors. One is actually a
> TRUE/FALSE factor, and I have coded it as 1/0, a continuous variable, but
> I could turn it back into a factor. The second is an ordered factor and
> consists of five timepoints. There are sever
Hello guys, I wanted to thank you, each one of you led me step by step to the
core of the problem. The matrix I was working on was made of rows obtained
each one by the lapply function. So by using lapply I was getting a matrix
which rows were not numeric vectors but lists. To solve this I used a
On Jan 29, 2010, at 6:53 PM, anna wrote:
Well I just tried to convert it with data.frame and then data.matrix
and it
returned me a numeric vector but I am not done yet, let's see if it
works,
if it doesn't I will try sapply. I think I didn't use sapply because
the
vectors I am using in
Well I just tried to convert it with data.frame and then data.matrix and it
returned me a numeric vector but I am not done yet, let's see if it works,
if it doesn't I will try sapply. I think I didn't use sapply because the
vectors I am using in lapply are of different lengths.
-
Anna Lippel
On Jan 29, 2010, at 6:14 PM, anna wrote:
Bill this is exactly what is happening, by using lapply I am having
a list
and not a numeric vector, I want a numeric vector, is there a way to
convert
that list to a numeric vector?
You could see if substituting sapply would yield a matrix. It w
Bill this is exactly what is happening, by using lapply I am having a list
and not a numeric vector, I want a numeric vector, is there a way to convert
that list to a numeric vector?
-
Anna Lippel
--
View this message in context:
http://n4.nabble.com/Simple-question-on-replace-a-matrix-row-
Dennis, as soon as I do : > mat3[1, ] <- mat1 and class(mat3) I get a list
and not a matrix anymore...So yes you drove me to the problem, mat1 is not
one-row numeric matrix but a list.
-
Anna Lippel
--
View this message in context:
http://n4.nabble.com/Simple-question-on-replace-a-matrix-
David, I think I am going close to the problem, at the end of the function
ComputeSignalReturns I build the matrix summary with cbind. So when I make
class(summary) I get "matrix" but when I make class(summary[1,]) I get
"list"
Excuse me if I didn't show the problem the right way, I am still new a
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of anna
> Sent: Friday, January 29, 2010 2:46 PM
> To: r-help@r-project.org
> Subject: Re: [R] Simple q
On Jan 29, 2010, at 4:54 PM, anna wrote:
I was trying to avoid the code because I wanted to simplify it but
here we
go:
mat2<- matrix(nrow = 30, ncol = 7)
colnames(mat2) <-c( "A", "B", "C", "D", "E", "F", "G")
mat1<-mainMat[1,]
I get mainMat[1,] from the following function:
Comput
What I did now is that I checked the class of both matrix before assigning
the first row of mat2:
class(mainMat) --> "matrix"
class(mainMat[1,]) --> "list"
class(mat2) --> "matrix"
mat2[1,]<-mainMat[1,]
class(mat2) --> "list"
I think the problem comes from mainMat[1,] that should be of class "mat
I was trying to avoid the code because I wanted to simplify it but here we
go:
mat2<- matrix(nrow = 30, ncol = 7)
colnames(mat2) <-c( "A", "B", "C", "D", "E", "F", "G")
mat1<-mainMat[1,]
I get mainMat[1,] from the following function:
ComputeSignalReturns <- function(vec1
1 - 100 of 136 matches
Mail list logo