similar to: indexing into a data.frame using another data.frame that also contains values for replacement

Displaying 20 results from an estimated 6000 matches similar to: "indexing into a data.frame using another data.frame that also contains values for replacement"

2011 Aug 18
2
Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?
Dear expeRts, What is the best approach to create a third data frame from two given ones, when the new/third data frame has last column computed from the last columns of the two given data frames? ## Okay, sounds complicated, so here is an example. Assume we have the two data frames: df1 <- data.frame(Year=rep(2001:2010, each=2), Group=c("Group 1","Group 2"), Value=1:20)
2009 Jan 21
3
merging several dataframes from a list
Hi there, I have a list of dataframes (generated by reading multiple files) and all dataframes are comparable in dimension and column names. They also have a common column, which, I'd like to use for merging. To give a simple example of what I have: df1 <- data.frame(c(LETTERS[1:5]), c(2,6,3,1,9)) names(df1) <- c("pos", "data") df3 <- df2 <- df1 df2$data
2008 Feb 19
2
Looping through a list of objects & do something...
Hey Folks, Could somebody show me how to loop through a list of dataframes? I want to be able to generically access their elements and do something with them. For instance, instead of this: df1<- data.frame(x=(1:5),y=(1:5)); df2<- data.frame(x=(1:5),y=(1:5)); df3<- data.frame(x=(1:5),y=(1:5)); plot(df1$x,df1$y); plot(df2$x,df2$y); plot(df3$x,df3$y); I would like to do something like:
2008 Feb 10
11
data frame question
Hello I have 2 data frames df1 and df2. I would like to create a new data frame new_df which will contain only the common rows based on the first 2 columns (chrN and start). The column score in the new data frame should be replaced with a column containing the average score (average_score) from df1 and df2. df1= data.frame(chrN= c(“chr1”, “chr1”, “chr1”, “chr1”, “chr2”, “chr2”, “chr2”),
2004 Mar 09
5
Adding data.frames together
I have a series of data frames that are identical structurally, i.e. - made with the same code, but I need to add them together so that they become one, longer, data frame, i.e. - each of the slot vectors are increased in length by the length of the added data frame vectors. So if I have df1 with a slot A so that length(df1$A) = 100 and I have df2 with a slot A so that length(df2$A)=200 then I
2009 Feb 19
3
Multiple merge, better solution?
Hello, My problem is that I would like to merge multiple files with a common column but merge accepts only two data.frames to merge. In the real situation, I have 26 different data.frames with a common column. I can of course use merge many times (see below) but what would be more sophisticated solution? For loop? Any ideas? DF1 <- data.frame(var1 = letters[1:5], a = rnorm(5)) DF2 <-
2011 Mar 18
1
Problem with Slope.test function
Hi all, I need to test the significnce of difference between slopes of two regression lines and regression line with theoretical line. I try to use Slope.test function from emu package, but an error occured... library(emu) d1<-data.frame(P1=c(1,2,3,5,7,8,9,13,14,15), P2=c(1,2,5,8,11,13,15,15,18,24), R=c(2,7,8,9,16,21,27,31,33,36)) # First data set m1<-lm(R~P1+P2+P1*P2,data=d1) # Regr.
2012 Jul 11
1
sapply question
Why does this sapply code change df3 but not df1? Thanks df1 <- read.table(text=" cola colb colc cold cole 1 NA 5 9 NA 17 2 NA 6 NA 14 NA 3 3 NA 11 15 19 4 4 8 12 NA 20 ", header=TRUE) df2 <-df1*2 df1 df2 df3 <-sapply(names(df1),function(x) {df1[[x]]<- df2[[x]]}) df1 df3 [[alternative HTML version deleted]]
2011 Jun 06
1
Merge two columns of a data frame
I have the following data: prefix <- c("cheap", "budget") roots <- c("car insurance", "auto insurance") suffix <- c("quote", "quotes") prefix2 <- c("cheap", "budget") roots2 <- c("car insurance", "auto insurance") roots3 <- c("car insurance", "auto
2003 Sep 04
1
error in lm.fit
Hello R user, I have several data frames with >100 columns and I did a linear regression over time of each column df1.lm <- lapply(df1, function(x) lm(x~year)$coeff[2]) that worked fine and I get slope of each column oder time - until I divided df1 by df2 df3 <- df1/df2 > df3.lm <- lapply(df3, function(x) lm(x~year)$coeff[2]) Error in lm.fit(x, y, offset = offset, ...) :
2012 Jul 18
2
duplicate data between two data frames according to row names
Hi everybody. I'll first explain my problem and what I'm trying to do. Admit this example: I'm working on 5 different weather stations. I have first in one file 3 of these 5 weather stations, containing their data. Here's an example of this file: DF1 <- data.frame(station=c("ST001","ST004","ST005"),data=c(5,2,8)) And my two other stations in
2005 Oct 20
1
Windows 2000 crash while using rbind (PR#8225)
Windows 2000 reports that "Rgui.exe has generated errors and will be = closed by Windows. You will need to restart the program." when using = rbind.=20 df1 <- data.frame(cbind(x=3D1, y=3D1:1000), fac=3Dsample(LETTERS[1:3], = 1000, repl=3DTRUE)) df2 <- data.frame(cbind(x=3D1, y=3D1:10), fac=3Dsample(LETTERS[4:6], = 10, repl=3DTRUE)) df3 <- data.frame(cbind(x=3D1,
2010 Dec 16
2
Compare two dataframes
Hello, I have two dataframes DF1 and DF2 that should be identical but are not (DF1 has some rows that aren't in DF2, and vice versa). I would like to produce a new dataframe DF3 containing rows in DF1 that aren't in DF2 (and similarly DF4 would contain rows in DF2 that aren't in DF1). I have a solution for this problem (see self contained example below) but it's awkward and
2010 Jan 22
2
Question on Merge/Lookup
I need to merge three datasets and don't know how. If I were using SQL, I would use df3, look up the characteristics of each date in df1 and the value for each observation in df2. df1 - unique list of Dates and characteristics of those dates Date, YYYYMM, YYYYWW, DOW df2 - the raw data Date, Place, Value df3 - all posibile combinations of Date + Place (via
2017 Jan 16
2
Error al fusionar tablas
Buenas tardes, Estoy tratando de fusionar dos data.frames pero no obtengo lo deseado. Un data.frame (Df1)tiene 53.657 observaciones (y 8 variables) que pertenecen una a cada individuo de la muestra. El otro (Df2) tiene 63.987 observaciones (y 17 variables), de los 53.657 individuos previos porque algun individuo tiene varias observaciones. Ambos solo coinciden por la variable
2006 Aug 13
2
How to order or sort a data.frame
I have a dataframe where I would like to order first by variable, year, and then within that variable by month. So far the only way that I have seen to do this is to order by year and then subset year and sort by month and then do an rbind to get things back together. Is this the right approach? Example: us.state <-rep("California", 23)
2012 Jun 03
2
merging single column from different dataframe
Hi all, probably really simple to solve, but having no background in programming I haven't been able to figure this out: I have two dataframes like df1 <- data.frame(names1=c('aa','ab', 'ac', 'ad'), var1=c(1,5,7,12)) df2 <- data.frame(names2=c('aa', 'ab', 'ac', 'ad', 'ae'), var2=c(3,6,9,12,15)) Now I want merge
2017 Jan 16
2
Error al fusionar tablas
Holabueno, aunque hay muchas posibilidades para fusionar ambas tablas, usando la tuya sería algo así:Df3<-merge(Df1,Df2,by="Reviewer.Username", all = TRUE) El Lunes 16 de enero de 2017 20:08, Jesús Para Fernández <j.para.fernandez en hotmail.com> escribió: Los data.frames para unirlos lo mejor es que tengan el mismo numero de columnas o variables. El dataframe2 
2009 Oct 07
1
merging dataframes with an unequal number of variables
Hallo Everyone I have the kind of problem that one should never have because one must always plan well and communicate with your team. But now I haven't so here is my problem. I have data coming in on a daily basis from surveys in 10 towns. The questionnaire has 62 variables but some of the regions have used older versions of the questionnaire that have a few variables less. I want to combine
2011 Oct 01
2
Help with cast/reshape
I realize that this is terribly basic, but I just don't seem to see it at this moment, so I would very much appreciate your help. How shall I transform this dataframe: > df1 ? Name Index Value 1??? a???? 1?? 0.1 2??? a???? 2?? 0.2 3??? a???? 3?? 0.3 4??? a???? 4?? 0.4 5??? b???? 1?? 2.1 6??? b???? 2?? 2.2 7??? b???? 3?? 2.3 8??? b???? 4?? 2.4 into this dataframe: > df2 ??? Index?