search for: row

Displaying 20 results from an estimated 16641 matches for "row".

Did you mean: now
2011 Sep 09
3
Read a list of files into named R data.frames
...h reads all the files, but doesn't create the R objects in the global environment. What is missing here? for (i in 1:length(files)) { inp <- read.csv(file=files[i], header=TRUE) name <- sub(".csv", "", files[i]) cat("Read ", files[i], "\trows: ", nrow(inp), " cols: ", ncol(inp), "\n") eval(paste(name, "<- inp")) } Read Allstar.csv rows: 4475 cols: 3 Read AllstarFull.csv rows: 4676 cols: 8 Read Appearances.csv rows: 94157 cols: 20 Read AwardsManagers.csv rows: 5...
2009 May 09
2
a general way to select a subset of matrix rows?
Dear fellow R users, I can't figure out how to do a simple thing properly: apply an operation to matrix columns on a selected subset of rows. Things go wrong when only one row is being selected. I am sure there's a way to do this properly. Here's an example: # define a 3-by-4 matrix x > x <- matrix(runif(12),ncol=4) > str(x) num [1:3, 1:4] 0.568 0.217 0.309 0.859 0.651 ... # calculate column means for selected...
2008 Jul 01
1
[.data.frame speedup
Below is a version of [.data.frame that is faster for subscripting rows of large data frames; it avoids calling duplicated(rows) if there is no need to check for duplicate row names, when: i is logical attr(x, "dup.row.names") is not NULL (S+ compatibility) i is numeric and negative i is strictly increasing "[.data.frame" <...
2011 May 25
1
rake task: uninitialized constant
...return nil end end namespace :import do desc ''import pericolanti'' task :pericolanti => :environment do UnsafeBuilding.delete_all puts "Creating unsafe_buildings..." lines = FasterCSV.read(''/home/user/Docs/pericolanti'') lines.each do |row| if row.any? # controllo che row[10] e row[11] non siano stringhe barrier_meters = row[10] if row[10].is_a?(Float) or row[10].is_a?(Integer) square_meters_public_land = row[11] if row[11].is_a?(Float) or row[11].is_a?(Integer) practice_number = row[17].to_i...
2013 Jan 22
2
Creating a Data Frame from an XML
Hello, I'm attempting to read information from an XML into a data frame in R using the "XML" package. I am unable to get the data into a data frame as I would like. I have some sample code below. *XML Code:* Header... Data I want in a data frame: <data> <row BRAND="GMC" NUM="1" YEAR="1999" VALUE="10000" /> <row BRAND="FORD" NUM="1" YEAR="2000" VALUE="12000" /> <row BRAND="GMC" NUM="1" YEAR="2001" VALUE="12500" />...
2018 Apr 21
2
Check if row of dataframe is superset of any row in another dataframe.
Hi, I am looking for a way in which I can check if rows in 1 dataframe are present in another data frame in a unique way. A row in dataframe should be super set of any row in another dataframe. I can write a for loop for it, however, that will be inefficient. So, I am looking for an efficient way to do this in R. I have explained it with an example b...
2007 May 01
5
duplicate key violates unique constraint
...e entries manually after the import. It complains about a duplicate primary key. I''ve tried Schedule.id += 1 but id= either isn''t defined or accessible in the class Here is my code: FasterCSV.foreach("schedule_store/#{@schedule_file.filename}", "r") do |row| unless row[3] == "CRN" # This would be faster as straight SQL if the current method # slows down too much. # # Would probably be cleaner with straight SQL too. self.associate(row[0], row[1]) self.first_name = row[0] self.la...
2008 Jan 11
3
Date range queries return zero results
Hello, I am having trouble getting data ranges to work correctly. I am using the following command to load the db: index << {:title => row[7].to_i, :date => Date.strptime(row[3], ''%Y-%m-%d''), :page_id => row[5].to_i, :page => row[6].to_i, :content_type => row[1].to_i, :article_id => row[4].to_i, :label =>...
2008 Oct 30
1
row.names(data.frame(matrixWithDimnames)) depends on first rowname being "" or not. (PR#13230)
Full_Name: Bill Dunlap Version: R version 2.9.0 Under development (unstable) (2008-10-29 r46795) OS: Linux Submission from: (NULL) (76.28.245.14) When data.frame() is given a matrix with rownames, then the type of the output row names depends on whether the first element of the input row names is "" or not. The other elements of the input row names don't affect things. E.g., > data.frame(matrix(1:6, nrow=3, ncol=2, dimnames=list(c("","Row 2",&qu...
2005 Oct 07
2
Some Ruby code help?
Hi, This isn''t related to Rails itself, but rather to Ruby. I''m trying to import a file into a database. The fields are separated by a ''|''. Everything seems to work fine, but after 64 rows are inserted, it starts mangling the field values. Would you take a look at the following code? require ''mysql'' def capitalize(str) str.downcase.gsub(/\b\w/) {|first| first.upcase } end def state(name, h) id = -1 h.query("SELECT id FROM states WHERE name = ...
2015 Mar 13
2
[PATCH] part-list: add support for show partition type
...as_m_opt) { - /* New-style parsing using the "machine-readable" format from - * 'parted -m'. - * - * lines[0] is "BYT;", lines[1] is the device line which we ignore, - * lines[2..] are the partitions themselves. Count how many. - */ - size_t nr_rows = 0, row; - for (row = 2; lines[row] != NULL; ++row) - ++nr_rows; - - r = malloc (sizeof *r); - if (r == NULL) { - reply_with_perror ("malloc"); - return NULL; + /* Old-style. Start at the line following "^Number", up to the + * next blank line. +...
2008 Feb 16
2
NoMethodError... but its not a method!
...e -%> <%= submit_tag ''Submit'' -%> <% end -%> Perhaps it is a naming problem? I am not sure. My controller looks like this: def bes @currenttime = Time.now @parsed_file = FasterCSV::parse(params[:dump][:file]) @parsed_file.shift n=0 @parsed_file.each do |row| c=Bes.new c.bes_id=row[0] # There are a bunch more of these lines, but this part works. c.bes_handheldconfigid=row[21] @besnumber = Bes.new params[:bes] if c.save n=n+1 GC.start if n%50==0 end Bes.delete_all(["created_at < ?", @currenttime]) flash.now[:messa...
2009 Mar 30
2
which rows are duplicates?
I would like to know which rows are duplicates of each other, not simply that a row is duplicate of another row. In the following example rows 1 and 3 are duplicates. > x <- c(1,3,1) > y <- c(2,4,2) > z <- c(3,4,3) > data <- data.frame(x,y,z) x y z 1 1 2 3 2 3 4 4 3 1 2 3 I can't figure...
2009 Mar 30
2
which rows are duplicates?
I would like to know which rows are duplicates of each other, not simply that a row is duplicate of another row. In the following example rows 1 and 3 are duplicates. > x <- c(1,3,1) > y <- c(2,4,2) > z <- c(3,4,3) > data <- data.frame(x,y,z) x y z 1 1 2 3 2 3 4 4 3 1 2 3 I can't figure...
2007 Apr 06
2
Reading a csv file row by row
Hi, my friends. When a data file is large, loading the whole file into the memory all together is not feasible. A feasible way is to read one row, process it, store the result, and read the next row. In Fortran, by default, the 'read' command reads one line of a file, which is convenient, and when the same 'read' command is executed the next time, the next row of the same file will be read. I tried to replicate such row-by...
2009 Jun 11
3
Matrix manipulation
Hello everyone, I have a couple of fairly simple questions (I hope) the answers to which I cannot find through the documentation at the moment. 1. I would like to delete the a row from a matrix if a certain elimination criterion is met. I am familiar with x <- x[-7,] (to remove row 7, for example). Are there any other means of removing an entire row? 2. Is there a single command that will rename the index of each row to match the row number once a row has been deleted....
2007 Mar 02
5
extracting rows from a data frame by looping over the row names: performance issues
Hi, I have a big data frame: > mat <- matrix(rep(paste(letters, collapse=""), 5*300000), ncol=5) > dat <- as.data.frame(mat) and I need to do some computation on each row. Currently I'm doing this: > for (key in row.names(dat)) { row <- dat[key, ]; ... do some computation on row... } which could probably considered a very natural (and R'ish) way of doing it (but maybe I'm wrong and the real idiom for doing this is something different). The pro...
2006 Apr 14
1
row.names in data.frame
We know from the White Book p.57 that the row names of a data frame `are never NULL and must be unique'. R documents that row.names() returns a character vector, and in R (much more so than on S) a long character vector of short unique strings is expensive to store (I saw 72 bytes/row on a 64-bit machine for 1:1e6). [Incidentally, in...
2006 Mar 01
3
Optimization problem: selecting independent rows to maximize the mean
Dear R community, I have a dataframe with 500,000 rows and 102 columns. The rows represent spatial polygons, some of which overlap others (i.e., not all rows are independent of each other). Given a particular row, the first column contains a unique "RowID". The second column contains the "Variable" of interest. The remaining 100 c...
2008 Dec 22
3
row sum question
Dear helpers, I'm using R version 2.8.0. Suppose that I have a small data set like below. [,1] [,2] [,3] [,4] a 1 1 0 0 b 0 1 1 0 c 1 1 1 0 d 0 1 1 1 First, I'd like to find row sum of values uniquely present in each row, but only sequentially from the top row, meaning that if the value is shown in the above row(s) already, the same value in the following row shouldn't be added into the sum. The result should be like this: row.sum [1] 2 1 0 1 And if a and c...