similar to: Add col in data.frame

Displaying 20 results from an estimated 600 matches similar to: "Add col in data.frame"

2011 Aug 29
2
Problem in writing a R data frame to Excel format using RODBC package
Hi Experts, I was trying to write a data frame which has a header row, from R to Excel disk file using RODBC ( RODBC_1.3-1) package. I met with an issue:- If in sqlSave(), I set a parameter "colnames=FALSE" then I get first row as header in excel file. If 'colnames=TRUE' then it gives me first 2 rows as header in excel file. Actually, according to my
2011 Nov 23
1
Losing custom attributes
Hi All, I was adding a new row of data to my data frame using rbind(). I was surprised to see that after adding new row, I lost my data frame level attibute as well as col level attribute. Please help me to insert a new row at frist or middle position so that my custom attribute is not lost. Here is what I did. age<-c(15,20,18) weight<-c(40,42,30) ### creating my data frame
2011 Nov 23
2
SPSS F-test on change in R square between hierarchical models
Hi, I am wondering if anyone knows how to perform an F-test on the change in R square between hierarchical models in R? SPSS provides this information and a researcher that I am working with is interested in getting this information. Alternatively, if someone knows how I can calculate the test statistic (SPSS calls it F-change?) and dfs that would be helpful as well. The output and the test I am
2011 Oct 04
3
The use of period in function names and variable names
Hi, I am looking for some guidance on whether I can use the period(.) in function names and variable names. For example: my.function.name <- function(my.data.variable, my.radius, my.another.var, my.value = 10) { } Will this pose any problems regarding older and current version of R. -- SmartG [[alternative HTML version deleted]]
2011 Nov 24
3
Is there way to add a new row to a data frame in a specific location
Is there easy way (without copying the existing rows to a temporary location and copying back) to add a new row to a specific index location in an existing data frame? Example df = data.frame( A= c('a','b','c'), B=c(1,2,3), C=(10,20,30)) newrow = c('X', 100, 200) I want to add the newrow as the second row to the data frame df Please suggest a solution that is
2004 Jul 29
3
Editing Strings in R
I was wondering if there is a way of editting strings in R. I have a set of strings and each set is a row of numbers and paranthesis. For example the first row is: (0 2)(3 4)(7 9)(5 9)(1 5) and I have a thousand or so such rows. I was wondering how I could get the corresponding string obtained by adding 1 to all the numbers in the string above. Dursun [[alternative HTML version deleted]]
2006 May 12
7
RJS and page.select collection size
I need to implement a conditional in my RJS template which looks something like: if (page.select(''row1'').first != null) page << "new TableRow.MoveAfter(''row1'', ''newrow'');" else page << "new TableRow.MoveAfter(''row2'', ''newrow'');" end Now, dumb question.. My
2008 Oct 15
2
R: "in-place" appending to a matrix.
Hello fellow R sufferers, Is there a way to perform an appending operation in place? Currently, the way my pseudo-code goes is like this for (i in 1:1000) { if (some condition) { newRow <- myFunction(myArguments) X <- rbind(X, newRow) # <- this is the bottleneck!! } } As you can see, it works but as the matrix X gets the size of a few million rows, the
2011 Apr 28
1
Trying to perform an inner loop a random number of times
Grateful for any hints as to why I'm not getting the inner loop to cycle the expected number of times. Code and one run's results below. Thanks, Galen > # source("looptest.r") > sp<-numeric() > iter<-numeric() > rn<-numeric() > ds<-data.frame(sp, iter, rn) > > for (sp in c(1:6)) { + i<-1 +
2010 Feb 06
1
duplicating records
Dear friends, I need to fill in (duplicate the whole record) the missing days with the same record values as long as AE is the same value (i.e. "1"), once AE value changes, the process of duplication should proceed with the new AE value till it changes again. e.g. I need to fill in records: day 18-day 44, all the records are carried with the new AE value of "0". At the
2010 Aug 13
1
loop for inserting rows in a matrix
Dear R friends, I have a matrix with 2060 rows and 41 columns. One column is Date, another is Transect, and another is Segment. I want to ensure that there are 9 Transects (1 to 9) for each Date, and 8 Segments (1 to 8) for each Transect in the matrix, by inserting rows where these are missing. I am new to coding, but am trying to write a loop which checks if each of the transects already
2011 Apr 25
1
Trouble Passing a for loop variable (iteration #) to a data frame
Greetings - I am working on a piece of code to simulate vehicle times in and out in each of a number of parking spaces. At this stage, my code basically does what it is supposed to do but for the sequential number of each new parking event for a given space (i.e., the index of the loop variable). Instead of passing the index of the loop variable (iter) to the data frame, it passes the value
2011 Nov 12
1
With an example - Re: rbind.data.frame drops attributes for factor variables
When I use rbind() or rbind.data.frame() to add a row to an existing dataframe, it appears that attributes for the column of type "factor" are dropped. See the sample example below to reproduce the problem. Please suggest How I can fix this. Thanks, Sammy a=c("Male", "Male", "Female", "Male") b=c(1,2,3,4) c=c("great", "bad",
2005 Sep 27
8
prototype.js
Hi *, We don''t know if you guys are the right audience, but we got a problem with prototype.js we need to solve. Essentially, it is a compatibility bug with the IE. We wrote a component so it updates itself periodically using AJAX. we used the prototype.js to accomplish this (using the periodicalUpdater object). now the component works fine using firefox or opera, but NOT with IE. the
2004 Aug 13
2
how to plot an array with labels
How can i plot an array and instead of having on the x labels the indexes of the array I want to display an other String array of the same length
2008 Oct 21
2
Inserting a new row in a matrix
Hi guys, I need to insert a row to a matrix in a for loop. I have matrix named "Avg" which is a 5x4 matrix of zeros. I have a file named "A"(4 rows,14 columns) which I make a sample of it 5 times. each time I get the mean for each column and put the result in the "Avg" matrix. this is my code: Avg=matrix(0,5,4) > > for(i in 1:5){ + res=(A[sample(nrow(A),
2003 Sep 11
2
(structured) programming style
I find that because R functions are call by value, and because there are no pointer or reference types (a la C++), I am making fairly heavy use of lexical scoping to modify variables. E.g. outer <- function() { m <- matrix(0, 2, 2) inner <- function() { m[2,2] <<- 3 ... } } I am not too pleased with this, as it violates basic rules of structured programming, namely
2010 May 14
2
Subscripting a matrix-like object
I have an S3 class called "tis" (Time Indexed Series) which may or may not have multiple columns. I have a function "[<-.tis" that I've reproduced below. My question is this: inside of "[<-.tis", how can I distinguish between calls of the form x[i] <- someValue and x[i,] <- someValue ? In either case, nargs() is 3, and looking at the values
2010 May 14
2
Subscripting a matrix-like object
I have an S3 class called "tis" (Time Indexed Series) which may or may not have multiple columns. I have a function "[<-.tis" that I've reproduced below. My question is this: inside of "[<-.tis", how can I distinguish between calls of the form x[i] <- someValue and x[i,] <- someValue ? In either case, nargs() is 3, and looking at the values
2010 Mar 18
2
Pedigree / Identifying Immediate Family of Index Animal
I have a data frame containing the Id, Mother, Father and Sex from about 10,000 animals in our colony. I am interested in graphing simple family trees for a given subject or small number of subjects. The basic idea is: start with data frame from entire colony and list of index animals. I need to identify all immediate relatives of these index animals and plot the pedigree for them. We're