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(

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

2021-07-14 Thread Kai Yang via R-help
Hello List, I wrote a script below to compare the difference of data frames structure (and will do something else). First of all I save the file list in a data frame ora, then I use for loop to 1. load the data from two resource, 2. generate data structure into two data frames, 3.do the compares

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

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

2017-11-22 Thread Massimo Bressan
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) B_flag<-c(12,9,0,5,0) mydf<-data.frame(A, A_flag, B, B_flag) # this is my initial df mydf I want to get to this final situation i<-which(myd

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

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

2016-12-10 Thread Marlin JL.M
Dear all, I want to assign a list to one column of data.frame where the name of the column is a variable. I tried the following: Using R version 3.3.2 > df <- iris[1:3, ] > df # Sepal.Length Sepal.Width Petal.Length Petal.Width Species # 1 5.1 3.5 1.4 0.2 setos

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

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

2016-06-13 Thread Mark Fingerle
Dear all, In order to create plots comparing two measurements I am using the "xyplot" and "make.groups" functions (see script example below). Now I would like to assign a value to the variable names in the plot. Meaning: In the beginning of my script I assign a name(value) to a variable (for ex

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(!(

[R] assign color to subsets

2016-04-23 Thread ch.elahe via R-help
Hi I have the following df and I created two subsets but I don't know how to use these subsets as the colors of my plot. data.frame': 36919 obs. of 162 variables $TE :int 38,41,11,52,48,75,. $TR :int 100,210,548,546,. $Command :factor W/2229

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
- I hope this helps, John - John Fox, Professor McMaster University Hamilton, Ontario Canada L8S 4M4 web: socserv.mcmaster.ca/jfox From: R-help [r-help-boun...@r-project.org] on behalf of Val [valkr...@gmail.com]

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
Professor McMaster University Hamilton, Ontario Canada L8S 4M4 web: socserv.mcmaster.ca/jfox From: R-help [r-help-boun...@r-project.org] on behalf of Val [valkr...@gmail.com] Sent: April 8, 2016 10:21 PM To: r-help@R-project.org (r-help@r-project.org) Subject: [

[R] assign

2016-04-08 Thread Val
Hi all I am trying t extract a variable from a column ASk/20005-01-45/90 Alldatk/25-17-4567/990 I want to assign a variable to the numbers coming the first"-" x=01 for the first and x=17 for teh second I tried using gsub but did not work x=gsub("-") any help? [[altern

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: > [

[R] assign a vector to list sequence

2016-03-09 Thread Jan Kacaba
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: [[1]] [1] 1 [[1]] [2] 2 [[1]] [2] 3 What I need is this: [[1]] [1] 1 2 3 [[1]

[R] assign optimal cut-off to variable using Epi/pROC packages

2015-07-27 Thread Luigi Marongiu
Dear all, I am calculating the optimal cut-off for a test against a gold standard measure. I can determine the cut-off (in the following example 5.905) but I would like to assign it to an atomic variable so that the cut-off is updated every time the data is changed. I am using the ROC and roc funct

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

[R] assign variables to function output

2015-04-16 Thread merm
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 within the function are contained and the only output I can get is "return(value)" which is awkward to work with. Any suggestions? Ch

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

2015-01-21 Thread zuzana zajkova
b > 12 290 2011-11-19 08:56:54 a b a > 13 291 2011-11-19 09:19:39 b a b > > > > which results in desired solution. > > Cheers > Petr > > > > -Original Message- > > From: R-help [mailto:r-help-boun...@r-proj

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

2015-01-21 Thread PIKAL Petr
b > which results in desired solution. Cheers Petr > -Original Message- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of zuzana > zajkova > Sent: Tuesday, January 20, 2015 11:15 PM > To: r-help@r-project.org > Subject: [R] Assign value to a row in da

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

[R] Assign value to a row in dataframe

2015-01-20 Thread zuzana zajkova
Hi, I have probably basic question, but I would be happy if somebody could help me with this: I have a dataframe where I want to assign a value to other column copying the value in previous row under some condition. Here is an example (dput on the end of message): > test[278:290,]

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
almazó: T Bal [studentt...@gmail.com] > Küldve: 2014. március 12. 10:13 > To: r-help@r-project.org > Tárgy: [R] Assign numbers in R > > 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: > &g

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
Feladó: r-help-boun...@r-project.org [r-help-boun...@r-project.org] ; meghatalmazó: T Bal [studentt...@gmail.com] Küldve: 2014. március 12. 10:13 To: r-help@r-project.org Tárgy: [R] Assign numbers in R Hi, I have the following numbers: d <- c(8,7,5,5,3,3,2,1,1,1) I want to convert these

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) > >

[R] Assign numbers in R

2014-03-12 Thread T Bal
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 they are same then assign the same number: r <- NULL for (i in 1:length(d)) { if (d[i] != d[i+1]) { r[i]

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

[R] Assign date according to defined time interval

2013-10-15 Thread Weijia Wang
Hi, I have something very interesting: Say I have this: 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 Now, I have time interval, week 1: from 9-Dec-12 to 15-Dec-12, wee

[R] Assign Observations to Tree Nodes

2013-03-18 Thread Jeff Coughlin
Hi, is there a way to assign observations from a dataset to nodes of a tree?   For example, if I have a data frame like the following: ID Var1 Var2 Var3 … VarX 1           .           .           .           n           And then run a classification tree with th

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
#10 10 2 2 4 > A.K. > > > > > - Original Message - > From: Lilia Dmitrieva > To: r-help@r-project.org > Cc: > Sent: Wednesday, March 13, 2013 3:05 PM > Subject: [R] Assign the number to each group of multiple rows > > Dear R users, > > > &

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
1   2 #5    5   2   2   2 #6    6   2   3   2 #7    7   1   1   3 #8    8   1   2   3 #9    9   2   1   4 #10  10   2   2   4 A.K. - Original Message - From: Lilia Dmitrieva To: r-help@r-project.org Cc: Sent: Wednesday, March 13, 2013 3:05 PM Subject: [R

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

2013-03-13 Thread Lilia Dmitrieva
Dear R users, My data have repeating "beh" parameter : 1 or 2 - type of animal behavior in subsequent locations. I need to assign unique number to each sequence of locations. My data is: >data=data.frame(row=seq(1:10),beh=c(1,1,1,2,2,2,1,1,2,2)) >attach(data) >data row beh 111

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

2013-02-24 Thread PIKAL Petr
ary 23, 2013 1:35 AM > To: r-help@r-project.org > Subject: [R] assign index to colnames(matrix) > > 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 c

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

[R] assign index to colnames(matrix)

2013-02-22 Thread Prew, Paul
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 names to my matrix ScoutRSM.mat using a for

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

[R] assign vectors to objects

2012-08-01 Thread John linux-user
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 (x in listfiles) {     dat=read.delim(x,header=F)    

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

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

2012-06-28 Thread lynx
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, l=0; p_int_sum=0; do i=1 to 8; do j=(i

[R] assign() and paste() for data.frame() in nested for loops

2012-04-24 Thread jssdenton
Hi folks, I am trying to recurse through several subfolders in a directory. Each folder has many entries that I want to display summary values for. I have been expanding data frames using code with the structure name <- rbind(name, newvals) to produce a data frame with n rows equal to the number o

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

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

2012-04-10 Thread aajit75
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 200 then seg should take value 1, ##if variable x2 gt 100

[R] Assign names to the assets in portfolio frontier plot. Using frontierPlot fPortfolio.

2012-03-21 Thread PaulK
Hi, I have troubles to assign names to the assets in the portfolio frontier plot using frontierPlot() in fPortfolio package. Can anyone please help me? If I use tailoredFrontierPlot in fPortfolio the assets assign names but I dont want to plot capital market line e.t.c. Someone maybe know how to d

Re: [R] assign a value to an element

2012-03-19 Thread John Kane
ahoo.fr > Sent: Sun, 18 Mar 2012 18:24:34 + (GMT) > To: r-help@r-project.org > Subject: [R] assign a value to an element > > Assign can be used to set a value to a variable that has name as a value > of another variable. Example: > >> name<-"essai" >&

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
h 18, 2012 11:25 AM > To: r-help@r-project.org > Subject: [R] assign a value to an element > > 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, "

[R] assign a value to an element

2012-03-18 Thread Marc Girondot
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 and so on that must be changed. > vec<-1:10 > vec  [1

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

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

2012-02-15 Thread agent dunham
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, xlab = "var1", ylab = "var2", col =var3 , b

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<-

[R] Assign and cmpfun

2012-01-06 Thread Michael Pearmain
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 <- function(x) { print(x + 1)} > foo <- function

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

  1   2   >