similar to: How to combine two rows (in a dataframe) into a third row?

Displaying 20 results from an estimated 30000 matches similar to: "How to combine two rows (in a dataframe) into a third row?"

2009 Nov 23
1
using contents of one column to direct addition of new rows in dataframe
Hello, R gurus. I've been trying to get R to do some data manipulation for me, and so far have been stumped in figuring out any elegant way to do so. Searches through the R-help archive haven't helped, so now I'm trying plan B. Suppose I have a dataframe that summarizes events that took place between some interval of time in days, "Time." I want to expand the dataframe to
2012 Aug 23
1
Extracting data from dataframe with tied rows
Hi R help, I'm a fairly experienced R user but this manipulation has me stumped, please help: DATA id<-rep(LETTERS[1:5],20) distance<-rnorm(1:100, mean = 100) bearing<-sample(1:360,100,replace=T) month<-sample(1:12,100,replace=T) I have a dataset with records of individuals (id) , each with a distance (distance) & direction (bearing) recorded for each month (month). I want
2009 May 14
1
Supplying NA or Zeros in dataframe for missing factor combinations
Hi there, I am not getting anywhere near a solution, so here is my question. I have searched the archives and didn't find a solution, but maybe my search didn't use the right words. So here it is: I have a dataframe with the following structure factor1 factor2 value In the (rather large) dataset I have to work on, there are some factor combinations missing, e.g. factor1 <-
2011 Oct 31
3
Plot two matrices and keeping the record of row names
Dear all, I have two data frames- x1 and y1 with same row names and column names(actually the names of the patients). x1 a b c d e a 1.0000000 0.4730679 0.6226994 0.6036036 0.6433333 b 0.4730679 1.0000000 0.6227273 0.6303855 0.5730858 c 0.6226994 0.6227273 1.0000000 0.7290503 0.6900585 d 0.6036036 0.6303855 0.7290503 1.0000000
2009 Nov 05
2
Merge records in the same dataframe
Hi: Suppose that I have a data frame as below x1 x2 x3 ... x10 wk1 wk2 ... Wk208 (these are the column names) For each record, x1, x2, x3 ... x10 are attributes. and wk1, wk2, ..., wk208 are the sales recoreded for this attribute combination. Suppose that now, that I want to do the following 1. Merge the data frame so that I have a new data frame grouped by values of x2 and x3 (for example).
2009 Nov 18
1
row-wise means
I have a dataframe with 3 columns. The first column stores an index. I would like to calculate the mean of the numbers stored in each of the rest of the columns. So, here is my data matrix: col1 col2 col3 1 23 34 2 45 56 3 23 56 4 34 68 For each row I would like to calculate the means of the numbers stored in col2 and col3. How can this be done in R? TIA, Anjan -- =============================
2009 Jul 21
4
How to extract the upper xlim and ylim of my plot?
Dear R-helpers, I wish to place some text in a plot, at approx 10% of my upper xlim and approx 90% of my upper ylim, i.e. > plot(log(all$SR,10)~log(all$AREA,10)) > text(.1*max(xlim),.9*max(ylim),"text to be placed") (I know how to give absolute coordinates for text location, but I wish to use relative coordinates). My code (above) doesn't work because I don't know how
2008 Dec 11
5
Row order in plot
I'm new to R so forgive me if this seems like a simple question: So I have table where the row titles are string variables. When I plot the data with rows along the x-axis, the data is ordered alphabetically as opposed to the order of the table. How can I preserve the row order of the table in the plot? Thanks in advance. -- View this message in context:
2011 Oct 04
2
Create combinations of rows
I don't quite know how to word what I want, but if I have (1, 2, 3); (a, b, c); (x, y) I want: 1 a x 1 b x 1 c x 1 a y 1 b y 1 c y 2 a ... and so forth What is the appropriate command? Best, Don -- View this message in context: http://r.789695.n4.nabble.com/Create-combinations-of-rows-tp3872641p3872641.html Sent from the R help mailing list archive at Nabble.com.
2010 Aug 25
2
find most repeated item from column in dataframe
R users, I am trying to find some way to find the value of a column that is repeated the most for each StandID of a dataframe. I have research methods online and the help page, but have had no success in finding a solution. I have tried using the table function but it returns items for the whole dataset and not by the StandID. Any help will be appreciated. Thanks in advance. R version 2.11.1
2010 May 20
2
How to extract rows from data frame based on unique variable groupings
R community, I would like to know how to extract rows from a data frame (DF) such that each row in the new data frame (D.F) represents the first instance of a unique variable pairing in the original dataframe (ordered first by variable V1 then by variable V2). The unique function does not seem to be able to accomplish this. I imagine there must be a simple solution for this, but I can't
2008 Mar 25
2
Combining logical operators to extract columns from a dataframe
Hi R-helpers, I have a dataframe (called data) with 100 columns, the columns of which are named with integers ranging from 1900 to 1999. I wish to extract those columns which names are >=1950 and <=1970. I tried: data2<-subset(data,select=(names(data)>=1950 & names(data)<=1970)) but that doesn't work. Any ideas? Thanks! Mark [[alternative HTML version deleted]]
2009 Nov 24
2
How to identify the rows in my dataframe with a negative value in any column?
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091124/27851110/attachment-0001.pl>
2010 Feb 23
3
how to rearrange a dataframe
Hi all, I'd appreciate if anyone can help me with this... I have a data frame that looks like this: 1 + name1 1 2 3 2 + name2 5 9 10 2 - name3 56 74 93 1 - name4 65 75 98 I need to rearrange this in a way so that the rows with "1" in the first column, and "-" in the second column; then columns 4 and 6 should switch places. That is, column 6 would be now column 4 and
2009 Jun 17
2
How to translate a dataframe into the R code that makes that dataframe?
Hi, I am helping another R user (off list) and I would like to email her an R script containing the data she needs and the code to solve her problem. I have made a small dummy dataset, but instead of sending her a CSV I would prefer to send the data embedded in the script, so there would be a like in the script like: my.df<-c( etc, etc, etc I have made the dataframe (in a spreadsheet) and
2010 May 19
1
export dataframe's column classes to a list
Hi Folks, I want to export a dataframe's column classes to a list so that I can reinstantiate the dataframe from a CSV file in the future. (I know about save(), which I'm using in addition to this). what I want to do is the following: write.csv(myframe); col_classes = get_col_classes(myframe); write.csv(col_classes, "column_classes") ... time passes, R gets
2006 Feb 24
2
Sorting a dataframe by one column?
Given the following dataframe: A=1:10 B=(a-5)^2 DATAFRAME=data.frame(A,B) How can I sort DATAFRAME increasing (or decreasing, for that matter) by B without making reference to A, or any other column? I've read ?order and ?sort but cannot seem to figure this out. Thank you. Mark
2009 Mar 24
3
Summarizing each row into a frequency table
I have a matrix containing -1, 0, 1, however certain rows will not have all 3 numbers. I have written some codes to compute the frequency table of how many -1s, 0s, 1s per row, but it is very ugly and not efficient if there are more than 3 numbers. Please suggest. m <- rbind(sample(0:1, replace=T, 10), sample(-1:1, replace=T, 10)) m.table <- t(apply(m, 1, function(x) c(sum(x==-1, na.rm=T),
2009 Jul 15
5
Grouping data in dataframe
Hello, I have a dataframe (obtained from read.table()) which looks like ExpA ExpB ExpC Size 1 12 23 33 1 2 12 24 29 1 3 10 22 34 1 4 25 50 60 2 5 24 53 62 2 6 21 49 61 2 now I want to take all rows that have the same value in the "Size" column and apply a function to the
2010 Jul 06
4
Adding two files into one and vlookup
I have two files with dates and prices in each. The number of rows in each of them will differ. How do I create a new file which contains data from both these files? Cbind and merge are not helpful. For cbind because the rows are not the same replication occurs. Also if I have similar data how do I write a vlookup kind of function? I am giving an example below: Say Price1 file contains the