search for: df2

Displaying 20 results from an estimated 528 matches for "df2".

Did you mean: df
2011 Mar 28
1
problem in simple saving and loading data frames
...table option), cost me time and sometime computer decomes not responsive. So I need a way to save my dataframe in my workdirectory as such. Execuse me if the problem is too simple. I tried the following, I do not know what is wrong with it: Example data: x <- 1:10 y <- 21:30 z <- 31:40 df2 <- data.frame(x,y, z) save(df2, file="df2.RData") My trials # trying to load data(df2) Warning message: In data(df2) : data set 'df2' not found data(df2.RData) Warning message: In data(df2.RData) : data set 'df2.RData' not found data("df2.RData") Warning m...
2013 Feb 26
2
merging or joining 2 dataframes: merge, rbind.fill, etc.?
#I want to "merge" or "join" 2 dataframes (df1 & df2) into a 3rd (mydf). I want the 3rd dataframe to contain 1 row for each row in df1 & df2, and all the columns in both df1 & df2. The solution should "work" even if the 2 dataframes are identical, and even if the 2 dataframes do not have the same column names. The rbind.fill funct...
2008 Sep 14
5
difference of two data frames
Hello I have 2 data frames DF1 and DF2 where DF2 is a subset of DF1: DF1= data.frame(V1=1:6, V2= letters[1:6]) DF2= data.frame(V1=1:3, V2= letters[1:3]) How do I create a new data frame of the difference between DF1 and DF2 newDF=data.frame(V1=4:6, V2= letters[4:6]) In my real data, the rows are not in order as in the example I provided...
2011 Dec 07
2
plotting and coloring longitudinal data with three time points (ggplot2)
...e so the assessment phase gets one color and the treatment phase another? I want to be able to show how long we have been in contact with our patients, how much of the contact time that was assessment and how much that was actual treatment. Below is an example (I call it the not-working example) df2 <- data.frame( ?date2 = seq(Sys.Date(), len= 156, by="2 day")[sample(156, 78)], ?patient2 = factor(rep(1:26, 3), labels = LETTERS) ) df2 <- df2[order(df2$date2), ] dt2 <- qplot(date2, patient2, data=df2, geom="line") dt2 + scale_x_date(major="months",...
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?
...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) df2 <- data.frame(Year=rep(2001:2010, each=2), Group=c("Group 1","Group 2"), Value=21:40) ## To make this a bit more fun, let's say the order of elements is different... (df1 <- df1[sample(1:nrow(df1)),]) (df2 <- df2[sample(1:nrow(df2)),]) ## Now I would like to creat...
2012 Dec 13
5
remove NA in df results in NA, NA.1 ... rows
...NA NA ... 44 574702.0 179754.0 NA NA NA NA NA NA NA NA 45 574695.1 179751.0 NA NA NA NA NA NA NA NA 46 574694.4 179752.0 NA NA NA NA NA NA NA NA Which I subset to df2 <- df[,c("X.PAD2","Y.PAD2")] df2 X.PAD2 Y.PAD2 73 574618.3 179650 74 574719.0 179688 75 574719.0 179688 76 574723.5 179678 77 574724.9 179673 78 574747.1 179598 79 574641.8 179570 80 574639.6 179573 81 574618.3 179650 82 NA NA 83 NA NA ....
2013 Jan 02
2
rbind: inconsistent behaviour with empty data frames?
The rbind on empty and nonempty data frames behaves inconsistently. I am not sure if by design. In the first example, first row is deleted, which may or may not be on purpose: df1 <- data.frame() df2 <- data.frame(foo=c(1, 2), bar=c("a", "b")) rbind(df1, df2) foo bar 2 2 b Now if we continue: df1 <- data.frame(matrix(0, 0, 2)) names(df1) <- names(df2) foo bar 2 1 a 3 2 b So now data frames combined successfully, but the row names have bee...
2012 Oct 11
1
as.data.frame.matrix() returns an invalid object
Hi, Two ways to create what should normally be the same data frame: > df1 <- data.frame(a=character(0), b=character(0))> df1 [1] a b <0 rows> (or 0-length row.names) > df2 <- as.data.frame(matrix(character(0), ncol=2, dimnames=list(NULL, letters[1:2]))) > df2 [1] a b <0 rows> (or 0-length row.names) unique() works as expected except that I get a warning on 'df2': > unique(df1) [1] a b <0 rows> (or 0-length row.names)...
2012 Sep 27
4
Colsplit, removing parts of a string
Hi, I am using colsplit (package = reshape) to split all strings in a column according to the same patterns. Here an example: library(reshape2) df1 <- data.frame(x=c("str1_name2", "str3_name5")) df2 <- data.frame(df1, colsplit(df1$x, pattern = "_", names=c("str","name"))) This is nearly what I want but I want to remove the words "str" and "name" from the values, because the columns are already named with that words. Is there a way to remove...
2009 Jan 21
3
merging several dataframes from a list
...) 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 <- c(6,2,9,7,5) df3$data <- c(9,3,6,2,1) mylist <- list(df1,df2,df3) names(mylist) <- c("df1","df2","df3") > mylist $df1 pos data 1 A 2 2 B 6 3 C 3 4 D 1 5 E 9 $df2 pos data 1 A 6 2 B 2 3...
2011 Apr 30
3
indexing into a data.frame using another data.frame that also contains values for replacement
...g to do is as follows: df1 <- data.frame(rows=c("A","B","C", "B", "C", "A"), columns=c("21_2", "22_2", "23_2", "21_2", "22_2", "23_2"), values=c(3.3, 2.5, 67.2, 44.3, 53, 66)) df2 <- data.frame(matrix(rep(NA, length(df1$values)),nrow=3, ncol=3)) names(df2) <- c("21_2", "22_2", "23_2") row.names(df2) <- c("A", "B", "C") > df1 rows columns values 1 A 21_2 3.3 2 B 22_2 2.5 3 C 23_...
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 s...
2012 Jul 11
4
Help with loop
Hi, I have two dataframes: The first, df1, contains some missing data: 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 The second, df2, contains the following: cola colb colc cold cole 1 1.4 0.8 0.02 1.6 0.6 I'm wanting all missing data in df1$cola to be replaced by the value of df2$cola. Then the missing data in df1$colb to be replaced with the corresponding value in df2$colb etc. I can get this to work column by col...
2012 Aug 14
4
Subsetting rows by multiple levels of selected values
Dear list, Let's say we have a data frame as follows, >expand.grid(a=1:5,b=c(1,5,10,20),DV=c(0.1,0.2,0.3))->df1 >df1$DV<-rgamma(60,shape=10) columns a and b are two levels. DV is the column with values we are interested in. Then another data frame df2 with values as follows data.frame(a=c(2,2,3,4,5),b=c(5,10,1,5,20))->df2 Now I want to a subset of df1 that match df2 at the both columns a and b. Any idea? Thanks. Jun [[alternative HTML version deleted]]
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: (pseudocode) dfarray[1] = df1 dfarray[2] = df2 dfarray[3] = df3 for (each i in dfarray) { plot(i$x, i$y); } Can this be done in R?...
2011 May 31
0
filling in a dataframe with another dataframe
Hello All, I have two dataframes and I wish to insert the values of one dataframe into another (let's call them DF1 and DF2). DF1 looks like this: col1.....col2 a...........1 b...........2 c...........3 d...........4 e...........5 f............6 g...........7 where col1 (which is just the first column of the dataframe) is a list of characters and col2 is the numeric value associated with col1 DF2 looks like this: co...
2007 Oct 02
4
Strange names when creating a data.frame: Difference between <- and =
This is just a curiosity question. Why do the two different syntaxes for df1 and df2 give such different results in the names(dfx)? Thanks df1 <- data.frame(nas = c("A", "B" , "B" ,"C" ,"B", "A", "D"),nums = c(3, 2, 1, 1, 2, 3, 7)) df2 <- data.frame(nas <- c("A", "B&qu...
2010 Dec 07
3
How to find out if a data frame has automatic row names?
...at I create myself, but what if a function needs to extract this information for an argument? The following example shows that this property is not easily visible: > # data frame with automatic row names > df <- data.frame(a=1:2, b=3:4) > # data frame with explicit row names > df2 <- data.frame(a=1:2, b=3:4, row.names=1:2) > # printing does not reveal any difference > df a b 1 1 3 2 2 4 > df2 a b 1 1 3 2 2 4 > # both are considered equal > all.equal(df, df2) [1] TRUE > identical(df, df2) [1] TRUE > # calling rownames gives the same result...
2011 Nov 08
2
compare linear regressions
Hi, I'm trying to compare two linear regressions. I'm using the following approach: ################## xx<-1:100 df1 <- data.frame(x = xx, y = xx * 2 + 30 + rnorm(n=length(xx),sd=10), g = 1) df2 <- data.frame(x = xx, y = xx * 4 + 9 + rnorm(n=length(xx),sd=10), g = 2) dta <- rbind(df1, df2) dta$g <- factor(dta$g) plot(df2$x,df2$y,type="l",col="red") lines(df1$x,df1$y,col="blue") summary(lm(formula = y ~ x + g + x:g, dta)) ################## I learned...
2007 Aug 19
2
How to parse a string into the symbol for a data frame object
I have several data frames, eg: > df1 <- data.frame(x=seq(0,10), y=seq(10,20)) > df2 <- data.frame(a=seq(0,10), b=seq(10,20)) It is common to create loops in R like this: > for(df in list(df1, df2)){ #etc. } This works fine when you know the name of the objects to put into the list. I assume that the order of the objects in the list is respected through the loop. Inside...