search for: newcol

Displaying 20 results from an estimated 39 matches for "newcol".

2010 May 17
1
suggestions/improvements for recoding strategy
...t data myData <- read.table(textConnection("id, v1, v2, v3 a,1,2,3 b,1-2,,3-4 c,,3,4"),header=TRUE,sep=",") closeAllConnections() # the first column is IDs so remove that numdat <- myData[,-1] # function to change dashes: 1-2 to 1.5 myrecode <- function(mycol) { newcol <- mycol newcol <- gsub("1-2","1.5",newcol) newcol <- gsub("2-3","2.5",newcol) newcol <- gsub("3-4","3.5",newcol) newcol <- as.numeric(newcol) } newData <- data.frame(do.call(cbind,lapply(numdat,myrecode)))
2009 May 26
1
Bug in "$<-.data.frame" yields corrupt data frame (PR#13724)
Full_Name: Steven McKinney Version: 2.9.0 OS: Mac OS X 10.5.6 Submission from: (NULL) (142.103.207.10) A corrupt data frame can be constructed as follows: foo <- matrix(1:12, nrow = 3) bar <- data.frame(foo) bar$NewCol <- foo[foo[, 1] == 4, 4] bar lapply(bar, length) > foo <- matrix(1:12, nrow = 3) > bar <- data.frame(foo) > bar$NewCol <- foo[foo[, 1] == 4, 4] bar X1 X2 X3 X4 NewCol 1 1 4 7 10 <NA> 2 2 5 8 11 <NA> 3 3 6 9 12 <NA> Warning message: I...
2006 Sep 13
7
inserting columns in the middle of a dataframe
Dear R users: Is there a built-in and simple way to insert new columns after other columns in a dataframe? I.e. currently I have: V1 V2 V3 V4 [1,] [2,] Etc. But I want V1 V5 V2 V3 V4 [1,] [2,] Etc. Can this be done in one line? Jon Minton [[alternative HTML version deleted]]
2018 Apr 15
4
Adding a new conditional column to a list of dataframes
...2012-01-05 2008-06-23 To add a new column where "C" has to be written in that column only if the date in "Tdate" column is less than the first date(row) in "Pdate" column.Otherwise "NA" is written. I have written this code to do so :- OneDF$NewCol [ OneDF[ ,3] < OneDF[ 1,2] ] <- "C" This gave me what I want as follows :- ID Pdate Tdate NewCol 1 2010-09-30 2011-05-10 NA 2 2011-11-07 2009-09-31 C 3 2012-01-05...
2009 Apr 29
1
Corrupt data frame construction - bug?
Hi useRs, A recent coding infelicity along these lines yielded a corrupt data frame. foo <- matrix(1:12, nrow = 3) bar <- data.frame(foo) bar$NewCol <- foo[foo[, 1] == 4, 4] bar lapply(bar, length) > foo <- matrix(1:12, nrow = 3) > bar <- data.frame(foo) > bar$NewCol <- foo[foo[, 1] == 4, 4] > bar X1 X2 X3 X4 NewCol 1 1 4 7 10 <NA> 2 2 5 8 11 <NA> 3 3 6 9 12 <NA> Warning message: In...
2010 Aug 09
1
creating pdf of wireframe
...details I have specified are not reproduced. For example, the line width I have specified is not reproduced, and neither are the font sizes for the axis labels. I'm an R novice, so I could really use some guidance. Here is the code I am using (post1, post2, post3 are 3-dimensional matrices): newcols <- colorRampPalette(c("grey90", "grey10")) #generates palette frome light to dark grey for better visibility trellis.device(pdf,file="PostAll.pdf", width = 5, height = 5) trellis.par.set("plot.line", list(lwd=0.15)); top.left <- wireframe(post1, xlab...
2011 Aug 01
1
Inserting column in between -- "better" way?
...via an R package. I leave it to you to define "essentially better." Thanks. Cheers, Bert On Mon, Aug 1, 2011 at 10:17 AM, Bert Gunter <bgunter at gene.com> wrote: > Doesn't work -- you lose column names. > > Try this instead: > > yourframe[,30:51] <- cbind( newcolumn,yourframe[,30:50]) > > Adjust column names after via: > > names(yourframe) [30:51] <- c(newcolname,names(yourframe[30:50]) > > Cheers, > Bert > > On Mon, Aug 1, 2011 at 10:10 AM, Sarah Goslee <sarah.goslee at gmail.com> wrote: >> x <- cbind(x[,1:29],...
2013 Jan 08
2
Applying a user-defined function
...above cut ()/quantile function to apply on different columns of the data frame > > CutQuintiles <- function(x) { + cut (test1$x,quantile (test1$x, (0:5/5)),include.lowest=TRUE) + } > > #apply the CutQuintile () on every odd-numbered columns of the "test1" data frame > newcols <- sapply(test1 [, seq (1,6,2)], CutQuintiles) Error in cut.default(test1$x, quantile(test1$x, (0:5/5)), include.lowest = TRUE) : 'x' must be numeric I would appreciate receiving your advice. Thanks, Pradip ###### The reproducible example begins here test1 <- read.table (text=...
2018 Apr 15
0
Adding a new conditional column to a list of dataframes
...; To add a new column where "C" has to be written in that column only if the date in > > "Tdate" column is less than the first date(row) in "Pdate" column.Otherwise "NA" is written. > > I have written this code to do so :- > > > OneDF$NewCol [ OneDF[ ,3] < OneDF[ 1,2] ] <- "C" > > > This gave me what I want as follows :- > > > ID Pdate Tdate NewCol > > 1 2010-09-30 2011-05-10 NA > > 2 2011-11-07 20...
2009 Feb 02
2
concatenating 2 text columns in a data.frame
...nate values from two columns in a data frame. For example, I have the following data.frame: C1 C2 C3 C4 C5 A B *F C* Q G H *I J* T K D *R S* E P L *M N* O I'd like to concatenate text from columns C3 and C4, to yield either a list or vector, like so: NewCol FC IJ RS MN Is this feasible in R? Thanks!
2018 Feb 25
4
reshaping column items into rows per unique ID
...a 3 j 4 c c f I tried many times using melt(),spread (),and dcast () functions but was not able to produce the desired table. The best attempt was by typing : # 1) Adding new column with unique values: MyDf $newcol <- c (1:9) #2) then : NewDf <- dcast (MyDf,CustomerID~newcol,value.var=DietType) This produces the desired table but with many NA values like this : CustomerID 1 2 3 4 5 6 7 8 9 1 a c b NA NA NA NA NA NA 2 NA NA NA f a...
2007 Mar 12
1
How to modify a column of a matrix
? stato filtrato un testo allegato il cui set di caratteri non era indicato... Nome: non disponibile Url: https://stat.ethz.ch/pipermail/r-help/attachments/20070312/5b30b712/attachment.pl
2008 Aug 20
3
vector operation using regexpr?
Hi, Here's my problem... I have a data frame with three columns containing strings. The first columns is a simple character. I want to get the index of that character in the second column and use it to extract the item from the third column. I can do this using a scalar method. But I'm not finding a vector method. An example is below. col1 col2 col3 'L'
2002 Feb 09
1
How to access objects outside an R function
Dear R-Users, I have a dataframe (''forexdata'') of daily returns from the foreign exchange market for three currencies - British Pound (bp), Canadian Dollar(cd), Deustche Mark (dm) vis-a-vis the US Dollar and the Date Of Trade(yymmdd). For some dates the returns are missing (recorded as zero) as there were no trades in that currency for that date. My task is to substitute the
2010 Jul 06
2
grayscale wireframe??
I need grayscale formatting for a wireframe. The only col.regions that I can find are color palettes are all colored: rainbow(n, s = 1, v = 1, start = 0, end = max(1,n - 1)/n, gamma = 1, alpha = 1) heat.colors(n, alpha = 1) terrain.colors(n, alpha = 1) topo.colors(n, alpha = 1) cm.colors(n, alpha = 1) The code follows: X11() library(lattice) par(family="serif", cex=1.2)
2018 Feb 25
0
reshaping column items into rows per unique ID
...j > 4 c c f > > I tried many times using melt(),spread (),and dcast () functions but was not able to produce the desired table. The best attempt was by typing : > > # 1) Adding new column with unique values: > MyDf $newcol <- c (1:9) > #2) then : > NewDf <- dcast (MyDf,CustomerID~newcol,value.var=DietType) > > This produces the desired table but with many NA values like this : > > CustomerID 1 2 3 4 5 6 7 8 9 > 1 a c b NA NA NA NA NA NA >...
2015 May 13
2
[LLVMdev] Modifying debug information through llvm pass
...ntly passed to executable binary. So if I use "addr2line" utility on the binary, it will return my modified debug information. I've tried to change by using the following code snippet: MDNode *N = Inst->getMetadata("dbg"); DebugLoc Loc = DebugLoc::get(newLine, newCol, N); Inst->setDebugLoc(Loc); I read the DebugLoc back by using const DebugLoc D = Inst->getDebugLoc(); unsigned Line = D.getLine(); outs() << Line <<"\n"; But I can't set the debug info correctly. How can I change the debug info correctly through...
2011 Oct 24
1
Creating data frame with residuals of a data frame
Dear experts, I am trying to create a data frame from the residuals I get after having applied a linear regression to each column of a data frame, but I don't know how to create this data frame from the resulting list since the list has differing numbers of rows. So for example: age<- c(5,6,10,14,16,NA,18) value1<- c(30,70,40,50,NA,NA,NA) value2<- c(2,4,1,4,4,4,4) df<-
2018 Feb 25
0
reshaping column items into rows per unique ID
...j > 4 c c f > > I tried many times using melt(),spread (),and dcast () functions but was > not able to produce the desired table. The best attempt was by typing : > > # 1) Adding new column with unique values: > MyDf $newcol <- c (1:9) > #2) then : > NewDf <- dcast (MyDf,CustomerID~newcol,value.var=DietType) > > This produces the desired table but with many NA values like this : > > CustomerID 1 2 3 4 5 6 7 8 9 > 1 a c b NA NA NA NA NA NA >...
2008 Aug 27
1
How to create additional columns?
I do have some data of dim 100*3 (i.e 100 rows and 3 columns ) stored in a txt file. I want to read the data into R, Perform the same operation in each row and store the result in a forth column( that I should create). I do not know how I can create a forth column to store the result of the operation for each row? -- View this message in context: