Re: [R] simple question on data frames assignment

2016-04-08 Thread ruipbarradas
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

Re: [R] simple question on data frames assignment

2016-04-08 Thread PIKAL Petr
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

Re: [R] simple question on data frames assignment

2016-04-08 Thread PIKAL Petr
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

Re: [R] simple question on data frames assignment

2016-04-07 Thread Michael Artz
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

Re: [R] simple question on data frames assignment

2016-04-07 Thread Michael Artz
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 > >

Re: [R] simple question on data frames assignment

2016-04-07 Thread Michael Artz
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

Re: [R] simple question on data frames assignment

2016-04-07 Thread Jeff Newmiller
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.

Re: [R] simple question on data frames assignment

2016-04-07 Thread Michael Artz
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

Re: [R] simple question on data frames assignment

2016-04-07 Thread ruipbarradas
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

Re: [R] simple question on data frames assignment

2016-04-07 Thread Hadley Wickham
== 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 <-

Re: [R] simple question on data frames assignment

2016-04-07 Thread Jeff Newmiller
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

Re: [R] simple question on data frames assignment

2016-04-07 Thread PIKAL Petr
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

Re: [R] simple question on data frames assignment

2016-04-07 Thread Michael Artz
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

Re: [R] simple question on data frames assignment

2016-04-07 Thread David Barron
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

Re: [R] SIMPLE question

2015-02-13 Thread S Ellison
> 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

Re: [R] SIMPLE question

2015-02-12 Thread JS Huang
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.

Re: [R] SIMPLE question

2015-02-12 Thread Rui Barradas
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

Re: [R] simple question - mean of a row of a data.frame

2015-02-11 Thread Kehl Dániel
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

Re: [R] simple question on loop

2012-11-16 Thread Suzen, Mehmet
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

Re: [R] Simple Question

2012-09-28 Thread Bert Gunter
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

Re: [R] Simple Question

2012-09-28 Thread Bhupendrasinh Thakre
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

Re: [R] Simple Question

2012-09-28 Thread Berend Hasselman
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

Re: [R] Simple Question

2012-09-28 Thread Bhupendrasinh Thakre
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"*.

Re: [R] Simple Question

2012-09-28 Thread Bhupendrasinh Thakre
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"*.

Re: [R] Simple Question

2012-09-28 Thread Bhupendrasinh Thakre
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

Re: [R] Simple Question

2012-09-27 Thread David Winsemius
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

Re: [R] Simple Question

2012-09-27 Thread Pascal Oettli
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

Re: [R] Simple Question

2012-09-27 Thread K. Elo
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)

Re: [R] Simple Question About Exporting Back to Excel

2012-09-26 Thread Rui Barradas
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

Re: [R] Simple Question About Exporting Back to Excel

2012-09-26 Thread David L Carlson
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

Re: [R] Simple Question About Exporting Back to Excel

2012-09-26 Thread ilai
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

Re: [R] Simple question about formulae in R!?

2012-08-10 Thread Joshua Wiley
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

Re: [R] Simple question about formulae in R!?

2012-08-10 Thread Bert Gunter
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

Re: [R] Simple question about formulae in R!?

2012-08-10 Thread S Ellison
> > 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

Re: [R] Simple question about formulae in R!?

2012-08-10 Thread David Winsemius
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,

Re: [R] Simple question about formulae in R!?

2012-08-10 Thread Joshua Wiley
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

Re: [R] Simple question about formulae in R!?

2012-08-10 Thread Henrik Singmann
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

Re: [R] Simple question about formulae in R!?

2012-08-10 Thread R. Michael Weylandt
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.

Re: [R] Simple question about formulae in R!?

2012-08-10 Thread ONKELINX, Thierry
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

Re: [R] Simple question on finding duplicates

2012-07-25 Thread arun
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

Re: [R] Simple question on finding duplicates

2012-07-25 Thread Peter Ehlers
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

Re: [R] Simple question on finding duplicates

2012-07-25 Thread Bert Gunter
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) >> >>

Re: [R] Simple question on finding duplicates

2012-07-25 Thread Bert Gunter
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

Re: [R] Simple question on finding duplicates

2012-07-25 Thread David L Carlson
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

Re: [R] Simple question on finding duplicates

2012-07-25 Thread David L Carlson
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

Re: [R] Simple Question?

2012-06-21 Thread Rui Barradas
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

Re: [R] Simple Question?

2012-06-21 Thread Bert Gunter
?? 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

Re: [R] simple question about max(x,y)

2012-05-15 Thread David Winsemius
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

Re: [R] Simple question regarding domain restrictions/piecewise functions in R

2012-03-26 Thread chad.mills
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

Re: [R] Simple question regarding domain restrictions/piecewise functions in R

2012-03-26 Thread Rolf Turner
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

Re: [R] Simple question regarding to specifying model

2011-10-12 Thread BvZ
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

Re: [R] Simple question regarding to specifying model

2011-10-12 Thread David Winsemius
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

Re: [R] Simple question about symbols()

2011-04-20 Thread murilofm
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

Re: [R] Simple question about symbols()

2011-04-20 Thread David Winsemius
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",

Re: [R] Simple question about symbols()

2011-04-20 Thread murilofm
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

Re: [R] Simple question about symbols()

2011-04-20 Thread Ben Bolker
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

Re: [R] Simple question about symbols()

2011-04-19 Thread David Winsemius
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:

Re: [R] Simple question about symbols()

2011-04-19 Thread murilofm
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

Re: [R] Simple question about symbols()

2011-04-19 Thread Ben Bolker
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

Re: [R] Simple question

2011-04-19 Thread Peter Ehlers
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

Re: [R] Simple question

2011-04-19 Thread peter dalgaard
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

Re: [R] Simple question

2011-04-19 Thread Marc Schwartz
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

Re: [R] Simple question

2011-04-19 Thread Rolf Turner
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

Re: [R] Simple question

2011-04-19 Thread David Winsemius
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

Re: [R] Simple question on eval

2010-12-01 Thread Joshua Wiley
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

Re: [R] Simple question on eval

2010-12-01 Thread Ivan Calandra
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

Re: [R] Simple question on eval

2010-12-01 Thread Lamke
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

Re: [R] Simple question on eval

2010-11-30 Thread Joshua Wiley
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

Re: [R] Simple question, name of the variable as string.

2010-09-17 Thread Barry Rowlingson
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

Re: [R] Simple question, name of the variable as string.

2010-09-17 Thread David Winsemius
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]

Re: [R] Simple question regarding name of column headers

2010-07-16 Thread jim holtman
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".

Re: [R] Simple question regarding name of column headers

2010-07-16 Thread Erik Iverson
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

Re: [R] Simple question regarding name of column headers

2010-07-16 Thread Ista Zahn
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

Re: [R] Simple question on binning data

2010-05-15 Thread Bernardo Rangel Tura
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

Re: [R] Simple question on binning data

2010-05-14 Thread Frank E Harrell Jr
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

Re: [R] Simple question on binning data

2010-05-14 Thread kMan
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. ..

Re: [R] Simple question on binning data

2010-05-13 Thread Dennis Murphy
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. > > >

Re: [R] Simple question on binning data

2010-05-13 Thread Rolf Turner
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

Re: [R] Simple question on binning data

2010-05-13 Thread Frank E Harrell Jr
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)

Re: [R] Simple question on binning data

2010-05-13 Thread Carl Witthoft
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

Re: [R] Simple question on binning data

2010-05-13 Thread Bert Gunter
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

Re: [R] Simple question on binning data

2010-05-13 Thread Erik Iverson
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

Re: [R] simple question

2010-04-22 Thread Carl Witthoft
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) }

Re: [R] simple question

2010-04-22 Thread Lee.Adams
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

Re: [R] simple question

2010-04-22 Thread David Winsemius
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

Re: [R] simple question

2010-04-22 Thread Muhammad Rahiz
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)

Re: [R] simple question

2010-04-22 Thread Joshua Wiley
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

Re: [R] simple question about contrasts, lm and factors

2010-04-12 Thread friendpine
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. ___

Re: [R] simple question about contrasts, lm and factors

2010-04-11 Thread Dieter Menne
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

Re: [R] Simple question on replace a matrix row

2010-02-01 Thread anna
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

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread David Winsemius
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

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
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

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread David Winsemius
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

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
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-

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
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-

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
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

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread William Dunlap
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

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread David Winsemius
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

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
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

Re: [R] Simple question on replace a matrix row

2010-01-29 Thread anna
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   2   >