Re: [R] assign a data frame name from a list in do loop

2021-07-14 Thread Kai Yang via R-help
Hello Rui, it's very helpful.  Thank you, Kai On Wednesday, July 14, 2021, 10:07:57 AM PDT, Rui Barradas wrote: Hello, Just before for(j in 1:nrow(ora)) include the following code line (I have removed the underscore): sdif <- vector("list", length = nrow(ora)) In the loop: sdif[[j

Re: [R] assign a data frame name from a list in do loop

2021-07-14 Thread Rui Barradas
Hello, Just before for(j in 1:nrow(ora)) include the following code line (I have removed the underscore): sdif <- vector("list", length = nrow(ora)) In the loop: sdif[[j]] <- sqldf(etc) Also, once again, why noquote? It's better to form file names with file.path: rdcsv  <- file.path(

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-23 Thread Bert Gunter
thanks > > m > > > - Messaggio originale - > Da: "Bert Gunter" > A: "Massimo Bressan" > Cc: "r-help" > Inviato: Mercoledì, 22 novembre 2017 17:32:33 > Oggetto: Re: [R] assign NA to rows by test on multiple col

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Massimo Bressan
same basic structure as the simplified example I posted thanks m - Messaggio originale - Da: "Bert Gunter" A: "Massimo Bressan" Cc: "r-help" Inviato: Mercoledì, 22 novembre 2017 17:32:33 Oggetto: Re: [R] assign NA to rows by test on multiple columns of

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Bert Gunter
Do you mean like this: mydf <- within(mydf, { is.na(A)<- !A_flag is.na(B)<- !B_flag } ) > mydf A A_flag B B_flag 1 8 10 5 12 2 NA 0 6 9 3 10 1 NA 0 4 NA 0 1 5 5 5 2 NA 0 Cheers, Bert Bert Gunter "The trouble with h

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Ek Esawi
Hi-- I too misread the question twice and i may have mistakenly posted non-text answer earlier. Below is a step by step solution that works provided that your real data frame has the same structure (alternative columns as in your example). You could combine all the steps in 2 statements. Best of

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Ek Esawi
OPS, Sorry i did not read the post carfully. Mine will not work if you have zeros on columns A and B.. But you could modify it to work for specific columns i believe. EK On Wed, Nov 22, 2017 at 8:37 AM, Ek Esawi wrote: > Hi *Massimo,* > > *Try this.* > > *a <- mydf==0mydf[a] <- NAHTHEK* > > On

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Ek Esawi
Hi *Massimo,* *Try this.* *a <- mydf==0mydf[a] <- NAHTHEK* On Wed, Nov 22, 2017 at 5:34 AM, Massimo Bressan < massimo.bres...@arpa.veneto.it> wrote: > > > Given this data frame (a simplified, essential reproducible example) > > > > > A<-c(8,7,10,1,5) > > A_flag<-c(10,0,1,0,2) > > B<-c(5,6,2,1,0

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Rui Barradas
;Rui Barradas" A: "Massimo Bressan" , "r-help" Inviato: Mercoledì, 22 novembre 2017 11:49:08 Oggetto: Re: [R] assign NA to rows by test on multiple columns of a data frame Hello, Try the following. icol <- which(grepl("flag", names(mydf))) mydf[icol] <- lapply

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Massimo Bressan
p" Inviato: Mercoledì, 22 novembre 2017 11:49:08 Oggetto: Re: [R] assign NA to rows by test on multiple columns of a data frame Hello, Try the following. icol <- which(grepl("flag", names(mydf))) mydf[icol] <- lapply(mydf[icol], function(x){ is.na(x) <- x == 0

Re: [R] assign NA to rows by test on multiple columns of a data frame

2017-11-22 Thread Rui Barradas
Hello, Try the following. icol <- which(grepl("flag", names(mydf))) mydf[icol] <- lapply(mydf[icol], function(x){ is.na(x) <- x == 0 x }) mydf # A A_flag B B_flag #1 8 10 5 12 #2 7 NA 6 9 #3 10 1 2 NA #4 1 NA 1 5 #5 5 2 0 NA

Re: [R] Assign a list to one column of data frame

2016-12-11 Thread Marlin JL.M
Dear Bert, This is awesome, thanks a lot! Best, Marlin On Sun, 2016-12-11 at 06:52 -0800, Bert Gunter wrote: > Use list indexing, "[[" not "[" . > > > df <- data.frame(a=1:3,b=letters[1:3]) > > x <- "new" > > df[[x]]<-  I(list(1:5,g = "foo", abb = matrix(runif(6),nr=3))) > > df > >   a b 

Re: [R] Assign a list to one column of data frame

2016-12-11 Thread Marlin JL.M
If you see my previous example, I have tried something like > df[,n3] <- I(mylist) However, in my case, the name of the new column is in a variable (by user input) which can not be directly used by the dollar assign. On the other hand, "[<-" does not work correctly even if I wrap the list into "

Re: [R] Assign a list to one column of data frame

2016-12-11 Thread Bert Gunter
Glad to help. However, I need to publicly correct my misstatement. Both "[[" and "[" can be used and are useful for list indexing. As ?"[" clearly states, the former selects only a single column, while the latter can select several. Also: "Both [[ and $ select a single element of the list. The m

Re: [R] Assign a list to one column of data frame

2016-12-11 Thread Bert Gunter
Use list indexing, "[[" not "[" . > df <- data.frame(a=1:3,b=letters[1:3]) > x <- "new" > df[[x]]<- I(list(1:5,g = "foo", abb = matrix(runif(6),nr=3))) > df a b new 1 1 a 1, 2, 3, 2 2 b foo 3 3 c 0.248115 > df$new [[1]] [1] 1 2 3 4 5 $g [1] "foo" $abb [,1]

Re: [R] Assign a list to one column of data frame

2016-12-11 Thread Bert Gunter
?data.frame says: "If a list or data frame or matrix is passed to data.frame it is as if each component or column had been passed as a separate argument (except for matrices of class "model.matrix" and those protected by I). " So doing what Help says to do seems to do what you asked: > df <- da

Re: [R] Assign value to plot variable name (make.group functions)

2016-06-13 Thread Bert Gunter
Mark: I do not understand what you mean by plot labels, which generally mean the x and y axis labels that can be given with xlab and ylab parameters in the xyplot call. Clearly, however, this is not what you mean. If you mean the labels in the key for the groups, you should create the grouping fac

Re: [R] assign color to subsets

2016-04-24 Thread jim holtman
Check the size of df_both. It would be that there are no Command fields that contain both a 't1' and 't2'. You can so do: sum(grepl("t1", df$Command) & grepl("t2", df$Command)) to see how many Command fields contain both. Jim Holtman Data Munger Guru What is the problem that you are trying t

Re: [R] assign color to subsets

2016-04-24 Thread ch.elahe via R-help
now after this: df_both <- subset(df, grepl("t1", Command) & grepl("t2", Command)) I use factor to apply the subset to df but then the Command level becomes 0 df_both$Command=factor(df_both$Command) str(df_both) $ Protocol : Factor w/ 0 levels: Do you know what is the r

Re: [R] assign color to subsets

2016-04-24 Thread jim holtman
'grepl' returns a logical vector; you have to use this to get your subset. You can use: df_tq <- subset(df, grepl("t1", Command)) df_t2 <- subset(df, grepl("t2", Command)) # if you want to also get a subset that has both, use df_both <- subset(df, grepl("t1", Command) & grepl("t2", Command))

Re: [R] assign color to subsets

2016-04-24 Thread ch.elahe via R-help
my problem is that in Command I have 2229 levels and I want to do subsets based on the names I have in Command. for example if the name has t1 or t2 in it or if it has both of them.and then I need to plot in a way that colors are names with t1,names with t2 and names with both. But now even t

Re: [R] assign color to subsets

2016-04-24 Thread jim holtman
You never did provide a reproducible example or say how you wanted to plot. Here is a way to get a subset of t1 or t2, and you can then use it as input to ggplot: library(dplyr) your_subset <- df %>% mutate(key = grep(".*(t1|t2).*", "\\1", Command, value = TRUE)) %>% filter(!(

Re: [R] assign

2016-04-09 Thread Fox, John
consistent structure to the strings (a second dash, which may be implied by the original question). Best, John > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Georges > Monette > Sent: April 9, 2016 3:04 PM > To: r-help@r-project.org > Sub

Re: [R] assign

2016-04-09 Thread Georges Monette
Hi, I couldn't resist these two suggestions: strings <- c("ASk/20005-01-45/90", "Alldatk/25-17-4567/990") x <- as.numeric(gsub("^[^-]*-|-.*$","",strings)) or x <- as.numeric(sub("^[^-]*-([0-9]+)-.*$","\\1",strings)) Best, Georges - Georges Monette, York University, Toron

Re: [R] assign

2016-04-08 Thread Jeff Newmiller
You are not using that function as it was designed to be used. You should read the help for gsub... ?gsub And if you don't know what the term "regular expression pattern" that is mentioned there means then you will probably need to study one of the many fine tutorials that are available on th

Re: [R] assign

2016-04-08 Thread Fox, John
Dear Val, Your question isn't entirely clear (to me), but this is what I think you want to do: -- snip > strings <- c("ASk/20005-01-45/90", "Alldatk/25-17-4567/990") > location <- regexpr("-[0-9]*", strings) > x [1] "01" "17" > x <- substring(strings, location +

Re: [R] assign a vector to list sequence

2016-03-09 Thread S Ellison
> > What I need is this: > > [[1]] > > [1] 1 2 3 > > [[1]] > > [2] 1 2 3 > > [[1]] > > [2] 1 2 3 Try rep(list(1:3), 3) S Ellison *** This email and any attachments are confidential. Any use...{{dropped:8}}

Re: [R] assign a vector to list sequence

2016-03-09 Thread Sarah Goslee
Hi, On Wed, Mar 9, 2016 at 10:22 AM, Jan Kacaba wrote: > Hello I would like to assign a vector to list sequence. I'm trying my code > bellow, but the output is not what inteded. > > # my code > mls=vector(mode="list") # my list > cseq=c(1:3) # my vector > mls[cseq]=cseq > > I get following: > [

Re: [R] assign variables to function output

2015-04-17 Thread MacQueen, Don
I don't disagree with the other answers, but I'd like to talk about what I see as a more underlying issue. Generally speaking, functions return the value of the last expression within them. myfun <- function(x) { z <- sqrt(x) 2 } Then y <- myfun(7) assigns 2 to y because 2 was the last expr

Re: [R] assign variables to function output

2015-04-16 Thread Sergio Fonda
That's it ! Sorry for writing in a hurry, Merm! Il 16/apr/2015 14:14, "Jim Lemon" ha scritto: > Hi merm, > In case Sergio's message is a little cryptic: > > return_a_list<-function() { > a<-"First item of list" > b<-c(2,4,6,8) > c<-matrix(1:9,nrow=3) > return(list(a,b,c)) > } > > x<-return_a_

Re: [R] assign variables to function output

2015-04-16 Thread Jim Lemon
Hi merm, In case Sergio's message is a little cryptic: return_a_list<-function() { a<-"First item of list" b<-c(2,4,6,8) c<-matrix(1:9,nrow=3) return(list(a,b,c)) } x<-return_a_list() x Jim On Thu, Apr 16, 2015 at 7:21 PM, Sergio Fonda wrote: > Collect in a vector or dataframe or list the

Re: [R] assign variables to function output

2015-04-16 Thread Sergio Fonda
Collect in a vector or dataframe or list the variables of interest and output it. Il 16/apr/2015 10:57, "merm" ha scritto: > Hi! > > So I'm trying as the header suggests to assign the value(s) output by a > function to a variable, say 'y' > > Problem is from what I gather any variables introduced

Re: [R] Assign value to a row in dataframe

2015-01-21 Thread zuzana zajkova
Hi Petr, your solution works also perfectly, thanks a lot! Again, I have learned new things :) (Sorry for problems with the dput...) Best wishes, Zuzana On 21 January 2015 at 11:57, PIKAL Petr wrote: > Hi > > I am not sure if I catch it correctly but from your example state has > preferen

Re: [R] Assign value to a row in dataframe

2015-01-21 Thread PIKAL Petr
Hi I am not sure if I catch it correctly but from your example state has preference over state new except in the case where state is 0. I would change state_bef 0 to NA and use na.locf function from zoo package. test$state_bef[test$state_bef=="0"] <- NA test$state_bef <- na.locf(test$state_bef,

Re: [R] Assign value to a row in dataframe

2015-01-21 Thread zuzana zajkova
Hi Jim, your code works just perfectly, it is exactly what I was looking for, thank you very much!!! I'm glad to learn something new, I haven't seen the use of "drow in 1:(dim(all)[1])" before. I made the code a bit shorter, excluding the use of "stat_bef" column, which I created just for my inte

Re: [R] Assign value to a row in dataframe

2015-01-20 Thread Jim Lemon
Hi Zuzana, >From your description it seems that you want to repeat the last "state_new" value when there are repeated zeros in both "state" and "state_bef". If that is the case, you may need to step through the data frame like this: for(drow in 1:(dim(test)[1])) { if(test$state[drow] != 0) test$s

Re: [R] Assign numbers in R

2014-03-12 Thread Arunkumar Srinivasan
Here's another one: match(d, unique(d)). Arun From: Greg Snow 538...@gmail.com Reply: Greg Snow 538...@gmail.com Date: March 12, 2014 at 8:41:31 PM To: T Bal studentt...@gmail.com Cc: r-help r-help@r-project.org Subject:  Re: [R] Assign numbers in R Here are a couple more optio

Re: [R] Assign numbers in R

2014-03-12 Thread Greg Snow
Here are a couple more options if you want some variety: > d <- c(8,7,5,5,3,3,2,1,1,1) > as.numeric( factor(d, levels=unique(d)) ) [1] 1 2 3 3 4 4 5 6 6 6 > cumsum( !duplicated(d) ) [1] 1 2 3 3 4 4 5 6 6 6 What would you want the output to be if your d vector had another 8 after the last 1? T

Re: [R] Assign numbers in R

2014-03-12 Thread T Bal
No, this is not a homework. Thank you so much! On Wed, Mar 12, 2014 at 10:39 AM, Kehl Dániel wrote: > Hi, > > is this homework? > Try > d <- c(8,7,5,5,3,3,2,1,1,1) > > r <- rep(1,length(d)) > > for (i in 2:length(d)) { > > if (d[i] != d[i-1]) { > r[i]=r[i-1]+1; > } > else { > r[i]

Re: [R] Assign numbers in R

2014-03-12 Thread arun
Hi, Try:  cumsum(c(TRUE,d[-1]!=d[-length(d)])) A.K. On Wednesday, March 12, 2014 5:28 AM, T Bal wrote: Hi, I have the following numbers: d <- c(8,7,5,5,3,3,2,1,1,1) I want to convert these into the following numbers: r: 1,2,3,3,4,4,5,6,6,6 So if two numbers are different increment it if t

Re: [R] Assign numbers in R

2014-03-12 Thread Kehl Dániel
Hi, is this homework? Try d <- c(8,7,5,5,3,3,2,1,1,1) r <- rep(1,length(d)) for (i in 2:length(d)) { if (d[i] != d[i-1]) { r[i]=r[i-1]+1; } else { r[i] = r[i-1]; } } Although I am sure there are better solutions! HTH daniel Feladó:

Re: [R] Assign numbers in R

2014-03-12 Thread Rui Barradas
Hello, Try the following. r <- cumsum(c(TRUE, diff(d) != 0)) Hope this helps, Rui Barradas Em 12-03-2014 09:13, T Bal escreveu: Hi, I have the following numbers: d <- c(8,7,5,5,3,3,2,1,1,1) I want to convert these into the following numbers: r: 1,2,3,3,4,4,5,6,6,6 So if two numbers are

Re: [R] Assign numbers in R

2014-03-12 Thread Pascal Oettli
Hello, For your example, the following will work: R> d <- c(8,7,5,5,3,3,2,1,1,1) R> idx <- 1:length(unique(d)) R> rep(idx, rle(d)$length) [1] 1 2 3 3 4 4 5 6 6 6 HTH, Pascal On Wed, Mar 12, 2014 at 6:13 PM, T Bal wrote: > Hi, > I have the following numbers: > > d <- c(8,7,5,5,3,3,2,1,1,1) > >

Re: [R] Assign date according to defined time interval

2013-10-16 Thread arun
Hi Weijia, This will give you the rownames of the split variables. lst1 <- split(a,list(a$COUNTRY,a$SITEID))  res <- t(sapply(lst1,function(x) {                 x$SCRNDT <- as.Date(x$SCRNDT, "%d-%b-%y")                 unlist(lapply(split(b,b$TMPT),function(y){                   sum(x$SCRNDT >=

Re: [R] Assign date according to defined time interval

2013-10-16 Thread arun
HI Weijia, Please check whether this is what you wanted. Weijia <- load("/home/arunksa111/Downloads/arun_help.RData" ) a[sapply(a,is.factor)] <-lapply(a[sapply(a,is.factor)],as.character) str(a)  b[sapply(b,is.factor)] <- lapply(b[sapply(b,is.factor)],as.character) str(b)  b$DT_ETP <- as.Date(b$D

Re: [R] Assign date according to defined time interval

2013-10-15 Thread arun
Hi, Please use ?dput() to show the dataset.  Also, it is not clear about how you store the time interval. dat <- read.table(text=" GroupID    Date 1  1  10-Dec-12 2  1  11-Dec-12 3  2  13-Dec-12 4  2  15-Dec-12 5  3  06-Dec-12 6  3  19-Dec-12",s

Re: [R] Assign the number to each group of multiple rows

2013-03-13 Thread Lilia Dmitrieva
This works too! Thank you. Such a relief after few days spent on trying to solve it. Lilia On 13 March 2013 19:52, jim holtman wrote: > I forgot the 'seq': > > > data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2)) > > data$tripid <- cumsum(c(TRUE, diff(data$beh) != 0)) > > data$seq <- ave

Re: [R] Assign the number to each group of multiple rows

2013-03-13 Thread Lilia Dmitrieva
Fantastic! Thank you so much On 13 March 2013 19:48, arun wrote: > Hi, > Try this: > data1<-data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2)) > data1<-within(data1, {trip.id<- cumsum(c(1,abs(diff(beh; Seq<-ave(row, > trip.id,FUN=seq)}) > data1 > # row beh Seq trip.id > #11

Re: [R] Assign the number to each group of multiple rows

2013-03-13 Thread jim holtman
I forgot the 'seq': > data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2)) > data$tripid <- cumsum(c(TRUE, diff(data$beh) != 0)) > data$seq <- ave(data$beh, data$tripid, FUN = function(x) seq_along(x)) > data row beh tripid seq 11 1 1 1 22 1 1 2 33 1 1

Re: [R] Assign the number to each group of multiple rows

2013-03-13 Thread jim holtman
try this: > data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2)) > data$tripid <- cumsum(c(TRUE, diff(data$beh) != 0)) > data row beh tripid 11 1 1 22 1 1 33 1 1 44 2 2 55 2 2 66 2 2 77 1 3 88 1 3 9

Re: [R] Assign the number to each group of multiple rows

2013-03-13 Thread arun
Hi, Try this: data1<-data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2)) data1<-within(data1, {trip.id<- cumsum(c(1,abs(diff(beh; Seq<-ave(row,trip.id,FUN=seq)})  data1 #   row beh Seq trip.id #1    1   1   1   1 #2    2   1   2   1 #3    3   1   3   1 #4    4   2   1   2 #5  

Re: [R] assign index to colnames(matrix)

2013-02-24 Thread PIKAL Petr
Hi What language are you comming from? colnames(ScoutRSM.mat) <- paste("X", 1:39, sep="") Regards Petr > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of Prew, Paul > Sent: Saturday, February 23, 2013 1:35 AM > To: r-help@r-p

Re: [R] assign index to colnames(matrix)

2013-02-22 Thread Prew, Paul
, 2013 7:22 PM To: Prew, Paul Cc: r-help@r-project.org Subject: Re: [R] assign index to colnames(matrix) On 02/23/2013 11:34 AM, Prew, Paul wrote: > Hello, I’m trying to follow the syntax of a script from a journal > website. In order to create a regression formula used later in the > sc

Re: [R] assign index to colnames(matrix)

2013-02-22 Thread Jim Lemon
On 02/23/2013 11:34 AM, Prew, Paul wrote: Hello, I’m trying to follow the syntax of a script from a journal website. In order to create a regression formula used later in the script, the regression matrix must have column names “X1�, “X2�, etc. I have tried to assign these column

Re: [R] assign estimated values

2013-02-11 Thread Rui Barradas
Hello, Em 11-02-2013 01:26, Pete Brecknock escreveu: malaka wrote Hi, I want to assign the ar1 , ma 1 and the intercept estimated by the following code to three variables a, b and c respectively. Can anyone help me with this please? code: a0 = 0.05; a1 = 0.1; b1 = 0.85 nu = rnorm(2500) epsi

Re: [R] assign estimated values

2013-02-10 Thread Pete Brecknock
malaka wrote > Hi, > I want to assign the ar1 , ma 1 and the intercept estimated by the > following code to three variables a, b and c respectively. > > Can anyone help me with this please? > > code: > > a0 = 0.05; a1 = 0.1; b1 = 0.85 > nu = rnorm(2500) > epsi = rep(0, 2500) > h = rep(0, 2500) >

Re: [R] assign vectors to objects

2012-08-01 Thread David Winsemius
On Aug 1, 2012, at 8:50 AM, John linux-user wrote: Hi everyone, I try to add many vectors (L1,L2,L3) to multiple list objects (a.list, b.list) in a workspace. Somethings like below, but it is not working. Any suggestions will be appreciated. Best, John lf=ls(pattern=".lst") for

Re: [R] assign vectors to objects

2012-08-01 Thread R. Michael Weylandt
I'm afraid I don't quite understand what you're getting at: can you say what you're trying to do big-picture wise. This advice might help making a reproducible example: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example Best, Michael PS -- Just a hunch -- but

Re: [R] assign object with loop (translation from SAS to R)

2012-06-29 Thread lynx
Dear Rui Barradas David Winsemius ONKELINX, Thierry David Carlson I really appreciate your helps. I did not realize that there were such many ways to do it. Among them, I just pick up the simple one and it worked out. It was like this. <> n <- 10 p <- 9 dataset <- data.frame(matrix(rep(seq

Re: [R] assign object with loop (translation from SAS to R)

2012-06-29 Thread David L Carlson
-project.org [mailto:r-help-bounces@r- > project.org] On Behalf Of ONKELINX, Thierry > Sent: Friday, June 29, 2012 10:11 AM > To: David Winsemius; lynx > Cc: r-help@r-project.org > Subject: Re: [R] assign object with loop (translation from SAS to R) > > You can use a combi

Re: [R] assign object with loop (translation from SAS to R)

2012-06-29 Thread ONKELINX, Thierry
. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens David Winsemius Verzonden: vrijdag 29 juni 2012 16:18 Aan: lynx CC: r-help@r-project.org Onderwerp: Re: [R] assign object with loop (translation from SAS to R) On Jun 28

Re: [R] assign object with loop (translation from SAS to R)

2012-06-29 Thread David Winsemius
On Jun 28, 2012, at 9:18 PM, lynx wrote: I have a dataset named DM with p1, p2, , p9 (9 columns, numerical values) I would like to calculate to multify each pair of columns (p1p2, p1p3,... p1p9, p2p3, p2p4 p8p9) and assign them in p1p2, p1p3,... p1p9, p2p3, p2p4 p8p9 In SAS,

Re: [R] assign object with loop (translation from SAS to R)

2012-06-29 Thread Rui Barradas
Hello, See inline. Em 29-06-2012 02:18, lynx escreveu: I have a dataset named DM with p1, p2, , p9 (9 columns, numerical values) I would like to calculate to multify each pair of columns (p1p2, p1p3,... p1p9, p2p3, p2p4 p8p9) and assign them in p1p2, p1p3,... p1p9, p2p3, p2p4 p8p9

Re: [R] Assign value to new variable based on conditions on other variables

2012-04-10 Thread David Winsemius
On Apr 10, 2012, at 8:59 AM, David Winsemius wrote: On Apr 10, 2012, at 3:16 AM, aajit75 wrote: I have got solution using within function as below dd$Seg <- 1 dd <- within(dd, Seg[x2> 0 & x3> 200] <- 1) In this instance the first of your assignments appears superfluous. dd <- within(dd,

Re: [R] Assign value to new variable based on conditions on other variables

2012-04-10 Thread David Winsemius
On Apr 10, 2012, at 3:16 AM, aajit75 wrote: I have got solution using within function as below dd$Seg <- 1 dd <- within(dd, Seg[x2> 0 & x3> 200] <- 1) In this instance the first of your assignments appears superfluous. dd <- within(dd, Seg[x2> 100 & x3> 300] <- 2) dd <- within(dd, Seg[x2>

Re: [R] Assign value to new variable based on conditions on other variables

2012-04-10 Thread Berend Hasselman
On 10-04-2012, at 08:44, aajit75 wrote: > Hi Experts, > > This may be simple question, I want to create new variable "seg" and assign > values to it based on some conditions satisfied by each observation. > > Here is the example: > ##Below are the conditions > > ##if variable x2 gt 0 and x3 gt

Re: [R] Assign value to new variable based on conditions on other variables

2012-04-10 Thread aajit75
I have got solution using within function as below dd$Seg <- 1 dd <- within(dd, Seg[x2> 0 & x3> 200] <- 1) dd <- within(dd, Seg[x2> 100 & x3> 300] <- 2) dd <- within(dd, Seg[x2> 200 & x3> 400] <- 3) dd <- within(dd, Seg[x2> 300 & x3> 500] <- 4) I sthere any better way of doing it!! -- View th

Re: [R] assign a value to an element

2012-03-19 Thread John Kane
I am not sure that I understand but does something like this do what you want? ec<-1:10 vec[vec==4] <- 100 vec <- 1:10 vec[ vec==4 | vec==8] <- 100 vec <- 1:10 aa <- 50 vec[vec==4] <- aa John Kane Kingston ON Canada > -Original Message- > From: marc_...@yahoo.fr > Sent: Sun, 18 Mar 2

Re: [R] assign a value to an element

2012-03-18 Thread David Winsemius
On Mar 18, 2012, at 2:24 PM, Marc Girondot wrote: Assign can be used to set a value to a variable that has name as a value of another variable. Example: name<-"essai" assign(name, "plouf") essai [1] "plouf" OK. But how to do the same when it is only an element of a vector, data frame an

Re: [R] assign a value to an element

2012-03-18 Thread William Dunlap
Do not use assign(). It is a relic from the 1980s. Instead, decide where you want your variables to live, perhaps in a list, where<-list() or perhaps in an environment, where<-new.env() or where<-environment(). Then use where[[varName]] to refer to the variable. You can use further subse

Re: [R] assign same legend colors than in the grouped data plot

2012-02-25 Thread R. Michael Weylandt
Your code isn't reproducible...(note the "legend " block -- that's not code) and (if I had to guess) it looks like you are using attach(). Don't do that... What do you mean it doesn't work? You say something about plotting lines, but your "working" code (the first block) doesn't do that... If

Re: [R] assign same legend colors than in the grouped data plot

2012-02-21 Thread agent dunham
Dear all, Thanks all of u for your help. Now I've another similar problem. I want to plot within the same plot, different lines, each one in a different color depending on the factor level. I've been able to do it like this, but if i try with rainbow colors it doesn't work. Can anybody help me wi

Re: [R] assign same legend colors than in the grouped data plot

2012-02-16 Thread Jim Lemon
On 02/16/2012 01:35 AM, agent dunham wrote: Dear community, I've plotted data and coloured depending on the factor variable v3. In the legend, I'd like to assign properly the same colors than in the factor (the factor has 5 levels). I've been trying this but it doesn't work. plot(var1, var2,

Re: [R] assign same legend colors than in the grouped data plot

2012-02-15 Thread R. Michael Weylandt
This is certainly not a reproducible example, but this works fine for me. lets = factor(sample(letters[1:3], 10, TRUE)) plot(1:10, 1:10, col = lets) legend("topleft", legend = levels(lets), col = seq.int(length(lets)), lty = 1) Michael On Wed, Feb 15, 2012 at 9:35 AM, agent dunham wrote: > Dear

Re: [R] Assign and cmpfun

2012-01-06 Thread Duncan Murdoch
On 12-01-06 12:18 PM, Michael Pearmain wrote: Hi All, I've just recently discovered the cmpfun function, and was wanting to to create a function to assign this to all the functions i have created, but without explicitly naming them. I've achieved this with: foo<- function(x) { print(x)} bar<-

Re: [R] Assign name to object for each iteration in a loop.

2011-12-03 Thread Patrick Connolly
On Thu, 01-Dec-2011 at 10:13AM -0800, lglew wrote: |> Hi R-users, |> |> I'm trying to produce decompositions of a multiple time-series, grouped by a |> factor (called "area"). I'm modifying the code in the STLperArea function of |> package ndvits, as this function only plots produces stl plots, i

Re: [R] Assign name to object for each iteration in a loop.

2011-12-01 Thread David Winsemius
On Dec 1, 2011, at 1:13 PM, lglew wrote: Hi R-users, I'm trying to produce decompositions of a multiple time-series, grouped by a factor (called "area"). I'm modifying the code in the STLperArea function of package ndvits, as this function only plots produces stl plots, it does not retu

Re: [R] Assign name to object for each iteration in a loop.

2011-12-01 Thread lglew
Thanks Michael! Yeah, that dealt with one of the problems. I still get the following error message: Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'list') cannot be handled by 'cat' I know that this has something to do with writing the names of the output file, an

Re: [R] Assign name to object for each iteration in a loop.

2011-12-01 Thread R. Michael Weylandt
I think part of your problem is the loop: you probably mean for(i in unique(area)) Michael On Thu, Dec 1, 2011 at 1:13 PM, lglew wrote: > Hi R-users, > > I'm trying to produce decompositions of a multiple time-series, grouped by a > factor (called "area"). I'm modifying the code in the STLperA

Re: [R] assign group letters to T/F matrix

2011-08-31 Thread Dimitris Rizopoulos
Have a look at package multcomp at: http://cran.r-project.org/package=multcomp I hope it helps. Best, Dimitris On 8/31/2011 2:30 PM, eldor ado wrote: dear R community, i appologize as this is kind of a newbie question, but: I want to assign group letters (like in anova post-hoc tests) to

Re: [R] assign using =

2011-06-27 Thread Gabor Grothendieck
On Mon, Jun 27, 2011 at 10:34 AM, Berry Boessenkool wrote: > > > Hey all, > > I learned that using the equals sign "=" to assign objects is generally OK, > but will not work in some cases. > As I always use "<-" for assignments, I have not encoutered any problems. > > Could somebody provide an ex

Re: [R] assign using =

2011-06-27 Thread Kevin E. Thorpe
On 06/27/2011 10:34 AM, Berry Boessenkool wrote: Hey all, I learned that using the equals sign "=" to assign objects is generally OK, but will not work in some cases. As I always use "<-" for assignments, I have not encoutered any problems. Could somebody provide an example or explanation, w

Re: [R] assign using =

2011-06-27 Thread David Stevens
I'm not an expert but some third party libraries won't recognize = as an assignment for some objects (I learned this empirically) when the assignment is made within a function. Using <- protects you from these unknows, as you have discovered on your own. Regards David On 6/27/2011 8:34 AM, Be

Re: [R] assign a cluster based on a variable

2011-06-09 Thread Dominik P.H. Kalisch
Oh, right. Now I see. Thanks for your help. Dominik On Thu, 09 Jun 2011 15:33:43 +0200, Uwe Ligges wrote: > On 09.06.2011 14:31, Dominik P.H. Kalisch wrote: >> Hi Uwe, >> >> thanks for your help. I didn't know that function (mea culpa)... >> With merge() it works what I want to do. >> But I'm st

Re: [R] assign a cluster based on a variable

2011-06-09 Thread Uwe Ligges
On 09.06.2011 14:31, Dominik P.H. Kalisch wrote: Hi Uwe, thanks for your help. I didn't know that function (mea culpa)... With merge() it works what I want to do. But I'm still interessted, for a learning purpose, why the loop didn't work. So here are the str() results: str(cluster) int [

Re: [R] assign a cluster based on a variable

2011-06-09 Thread Dominik P.H. Kalisch
Hi Uwe, thanks for your help. I didn't know that function (mea culpa)... With merge() it works what I want to do. But I'm still interessted, for a learning purpose, why the loop didn't work. So here are the str() results: > str(cluster) int [1:18, 1:2] 12051000 12052000 12053000 12054000 1206000

Re: [R] assign a cluster based on a variable

2011-06-07 Thread Uwe Ligges
On 07.06.2011 16:24, Dominik P.H. Kalisch wrote: Hi, I have two matrices of the following form: cluster (n=18): 12062 1 12063 2 12064 2 12065 3 12066 5 KreisSA (n=2304) 12062 12062 12067 12065 12063 12067 I try to assign the cluster[,2] to KreisSAa by the follwoing loop: n <- nrow(cluster)

Re: [R] assign $y of predict() function output to variable

2011-05-18 Thread David Winsemius
On May 18, 2011, at 1:35 PM, Asan Ramzan wrote: Hello R-help Below is the output from the predict() function. How can I assign $y to a variable. Newvar <- predict(function,df2)$y -- David. $x V1 1 36.28 2 34.73 3 33.74 4 69.87 5 58.88 6 89.44 7 43.97 8 41.94 9

Re: [R] Assign with Paste Problem

2011-04-12 Thread baptiste auguie
Hi, You probably need ?get, though you might want to read this first, library(fortunes) fortune(236) HtH, baptiste On 13 April 2011 13:04, Sparks, John James wrote: > Dear R Helpers, > > I am trying to change the name of an object using the assign function. > When I use paste on the new obje

Re: [R] Assign Character Value to Data Frame

2011-04-12 Thread Sarah Goslee
That column of your data frame contains a factor, rather than character values. You don't tell us how you created the data frame, but you might be interested in the stringsAsFactors option to data.frame() and read.table(). Or, if you do actually want a factor for that column, you can use factor()

Re: [R] Assign Character Value to Data Frame

2011-04-12 Thread Joshua Wiley
Hi John, The error arises because the "hold" data frame contains factors. This happens by default when creating data frames with character data as you did. Factors have a set number of levels and new values cannot be assigned to them that fall outside their specified levels, hence the error. Th

Re: [R] Assign Names of columns in data.frame dinamically

2011-04-01 Thread Andreas Borg
Hi Marcos, I'd be glad to help, but your example is not usable for anyone but yourself - I don't have the files that your code reads and I don't have any idea what the resulting data frames look like. Please provide examples of the data and the result. Andreas Marcos Amaris Gonzalez schrieb

Re: [R] assign value to multiple objects with a given ls pattern

2011-02-21 Thread Ivan Calandra
As I partially showed, I guess that the problem of assigning the value 99 to any object in the workspace can be dealt with a more precise regular expression. Maybe that would do: ls(pattern="^a[1-9]$") or ls(pattern="^a[0-9]+$") In any case, I agree that alternatives are better Ivan Le 2/21

Re: [R] assign value to multiple objects with a given ls pattern

2011-02-21 Thread Greg Snow
If instead of having a1, a2, etc. as global variables you put them into a list then this becomes simple. The general rule is that if you ever want to do the same (or similar) think to a set of variable, then they should not have been separate variables, but part of a bigger one. Lists work wel

Re: [R] assign value to multiple objects with a given ls pattern

2011-02-21 Thread Ivan Calandra
Hi, This works for me: pat <- ls(pattern="^a") ## I would anchor "a" to the beginning with "^" for safety! for (i in seq_along(pat))assign(pat[i], value=99) Or this with lapply: lapply(pat, FUN=function(x) assign(x, value=99, envir=.GlobalEnv)) See ?assign HTH, Ivan Le 2/21/2011 17:22, Nuno

Re: [R] assign value to multiple objects with a given ls pattern

2011-02-21 Thread Ista Zahn
Hi Nuno, Yes, you can do for(i in ls(pattern="a")) { assign(i, 99) } but honestly this is a bad idea. It will try to assign the value of 99 to any object in your workspace that contains an a, which sounds really scary to me. Better I think to use a list: ab.list <- list(a1=1, a2=2, a3=3, a4=4

Re: [R] assign factor levels based on list

2011-02-10 Thread Tim Howard
David and Bill, Thank you so much for your rapid and exceptional help. Bill, the reason I had gone with lists within the list was because I thought I might use the list for holding other information - and because it was easier to get the column name. Your simple-list suggestion is cleaner and I'

Re: [R] assign factor levels based on list

2011-02-09 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Tim Howard > Sent: Wednesday, February 09, 2011 12:44 PM > To: r-help@r-project.org > Subject: [R] assign factor levels based on list > > All, > > Given a data frame and a list

Re: [R] assign factor levels based on list

2011-02-09 Thread David Winsemius
On Feb 9, 2011, at 4:18 PM, David Winsemius wrote: On Feb 9, 2011, at 3:44 PM, Tim Howard wrote: All, Given a data frame and a list containing factor definitions for certain columns, how can I apply those definitions from the list, rather than doing it the standard way, as noted below.

Re: [R] assign factor levels based on list

2011-02-09 Thread David Winsemius
On Feb 9, 2011, at 3:44 PM, Tim Howard wrote: All, Given a data frame and a list containing factor definitions for certain columns, how can I apply those definitions from the list, rather than doing it the standard way, as noted below. I'm lost in the world of do.call, assign, paste, and

  1   2   >