search for: df1

Displaying 20 results from an estimated 578 matches for "df1".

Did you mean: df
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) 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 differ...
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 da...
2005 Jun 29
3
return NA
A<-c(1,2,NA,7,5) B<-c(3,4,1,4,1) C<-c(6,5,6,NA,9) D<-c(8,7,4,6,2) df1<-cbind(A,B,C,D) for(i in seq(1,ncol(df1)-1, by=2)) { ifelse(df1[,i]=="NA",df1[,i+1]=="NA",df1[,] ) } Tried several variations but none worked. I wish to find any NA's in column's 1 or 3 and change the numerical value to the right of the " NA"'s...
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...
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....
2012 Nov 22
4
Data Extraction
Hello, I would appreciate if someone could help me resolve the following: 1. df1[!is.na( X1 | X2 | X3 | X4 | X5),][,1:5] # This does not work 2. Is these message harmful? The following object(s) are masked from 'df1 (position 3)': X1, X2, X3, X4, X5 Thanks, Pradip Muhuri #Reproducible Example set.seed(5) df1<-data.frame(matrix(sample(c(1:10,NA),100,replace=...
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(...
2009 Nov 19
5
Accessing list names in lapply
Hi, When using lapply (or sapply) to loop over a list, can I somehow access the index of the list from inside the function? A trivial example: df1 <- split( x=rnorm(n=100, sd=seq(from=1, to=10, each=10)), f=letters[seq(from=1, to=10, each=10)] ) str(df1) #List of 10 # $ a: num [1:10] -0.801 0.418 1.451 -0.554 -0.578 ... # $ b: num [1:10] -2.464 0.279 4.099 -2.483 1.921 ... # $ c: num [1:10] -1.14 -1.773 2.512 -2.072 -0.904 ... # $ d...
2009 Sep 16
1
re-code missing value
...~ v3) are my observations. In the observations of the data set, "." indicates missing value. I replaced "." with NA. To replace "." with NA, I used two steps. First, I replaced "." with NA, and then, changed each variable from factor to numeric using "df1$v1 <- as.numeric(df1$v1)". The second step was OK when I have low numbers of variables, however, it is painful when I have a lot of variables. My question is: Is there any much more efficient way to convert this kind of large scale data? In short, I am looking for an alternative way of S...
2009 Feb 10
1
aggregate taking way too long to count.
...df <- data.frame(expand.grid('parameter'=LETTERS ,'station'=letters[1:10] ,'site'=1:100 ) ) df$parameter = as.character(df$parameter) df$station = as.character(df$station) df1 <- rbind(df, df[runif(nrow(df))>0.99,]) # add some duplicate parameters tt <- df1 system.time(tt <- aggregate(I(df1$parameter) ,list('site'=df1$site ,'station'=df1$station ,...
2011 May 12
2
Simple order() data frame question.
Clearly, I don't understand what order() is doing and as ususl the help for order seems to only confuse me more. For some reason I just don't follow the examples there. I must be missing something about the data frame sort there but what? I originally wanted to reverse-order my data frame df1 (see below) by aa (a factor) but since this was not working I decided to simplify and order by bb to see what was haqppening!! I'm obviously doing something stupid but what? (df1 <- data.frame(aa=letters[1:10], bb=rnorm(10))) # Order in acending order by bb (df1[order(df1[,2]),] ) #...
2010 Nov 19
3
Still confused with lapply
...million of rows) of what I would like to do, that is applying the same calculation to all the rows of the data frame (knowing that I cannot change the structure of the function). I hope you understand my french explainations ... Thanks in advance for your help, Have a nice week-end, Ptit Bleu. df1<-data.frame(c(1,2,3,4), c(9,6,5,8), c(5,4,8,6)) names(df1)<-c("C1", "C2", "C3") fcttest<-function(a1,a2,a3) { v<-a1*a2 w<-a2+a3 return(c(v,w)) } # The following for loop works result<-data.frame() for (i in 1:length(df1[,1])) { result<-rbind(...
2017 Jul 13
2
about plotting a special case
Thanks, Jim. The code works, but I don't understand why you use q1090 <- quantile(DF1$B, probs=c()), rather than DF1$A? Also, how to add a legend for both points DF1 and DF2? On Wed, Jul 12, 2017 at 8:25 PM, Jim Lemon <drjimlemon at gmail.com> wrote: > Hi lily, > Here is the first plot: > > plot(DF1$A,DF1$B,pch=19,col="red") > meanA<-mean(DF1$A) &...
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...
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 <- 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...
2016 Jun 23
2
Asignar a un dataframe un id de otro dataframe en función de intervalos con fechas
...rentemente parece muy sencillo: Tengo dos dataframe, en el primero tengo una serie de códigos con hora de inicio y hora de fin y en el segundo otros códigos asociados a una hora; Lo que necesito es crear una nueva variable en el segundo data frame que indique a qué intervalo del primer data frame (df1$id) pertenece cada nivel del segundo dataframe (df2$label). Os dejo un ejemplo reproducible: df1 <- data.frame(id=seq(1, 10, 1),begin=c("2012-09-06 09:34:00","2012-09-06 10:18:00","2012-09-06 10:53:00","2012-09-06 11:28:00","2012-09-06 12:02:00&quot...
2017 Jul 13
0
about plotting a special case
If you want colors mapped to the _values_ in DF1$C, there are a number of ways to do it: Color_unq<-color.scale(DF1$C,c(1,0),c(0,0,c(0,1)) This will produce colors from the lowest values (red) through the highest (blue). See the help page for color.scale to get different colors. With this you can use color.legend to add a mapping of the valu...
2011 Nov 30
1
Replace columns in a data.frame randomly splitted
Dear community, I'm working with the data.frame attached ( http://r.789695.n4.nabble.com/file/n4122926/df1.xls df1.xls ), let's call it df1. I typed: df1<- read.xls("C:/... dir .../df1.xls",colNames= TRUE, rowNames= TRUE) Then I splited randomly df1 using splitdf function (http://gettinggeneticsdone.blogspot.com/2011/03/splitting- dataset-revisited-keeping.html) So now, I ha...
2012 Nov 17
3
transform input argument (matrix) of function
...trix, which is input argument of a written function. It is easy with new matrix (see below), but my idea is to transform input argument (matrix) of function without any additional matrixes. Here is an example: fun1 <- function(xy) { xy <- cbind(xy[,1], xy[,2], xy[,1] + xy[,2]) return(xy) }   df1 <- matrix(c(1,2,3,1,2,3), ncol = 2) fun1(df1)   fun2 <- function(xy) { xy <- cbind(xy[,1], xy[,2], xy[,1] + xy[,2]) return(invisible(xy)) }   fun2(df1) df1 > should be      [,1] [,2] [,3] [1,]    1    1    2 [2,]    2    2    4 [3,]    3    3    6   Thanks to all for help, OV [[alterna...
2013 Jun 10
1
modify and append new rows to a data.frame using ddply
...reviously row i+1th [i+3]?01-01-2000 21:01:30 , 30 # previously row i+2th . . . I attach a dput with a selection of my data.frame. Here is a piece of existing code that I am trying to adapt just for the daytime/night time change: ? require(plyr) ? xandaynight <- ddply( xan, .(Ring), function(df1){ ? # index of day/night changes ? ind <- c( FALSE, diff(df$dif) == 1 ) ? add <- df1[ind,] ? add$timepos <- add$dusk ? # rearrangement ? df1 <- rbind( df1, add ) ? df1 <- df1[order(df1$timepos),] ? # recalculation of act ? df1$act2 <- c( diff( as.numeric(df1$timepos) ), NA ) ? df1...