Commit d708a6e6 authored by Virgile Baudrot's avatar Virgile Baudrot
Browse files

add join feature

parent 62511713
Pipeline #771 passed with stage
in 10 minutes and 56 seconds
......@@ -3,11 +3,13 @@
export(fd_add)
export(fd_add2)
export(fd_add_NAME)
export(fd_bind)
export(fd_filter)
export(fd_filter1)
export(fd_filter2)
export(fd_filter3)
export(fd_filter_)
export(fd_join)
export(fd_match)
export(fd_melt)
export(fd_melt_DOUBLE)
......
#' @name fd_join
#'
#' @title Join a list of data frame to a single data frame
#'
#' @description Join a list of data.frame to a single data.frame
#'
#' @param x object of class data.frame.
#' @param y object of class list
#' @param by a character vector of variables to join by. If NULL,
#' `fd_join` is equivalent to `fd_bind`.
#'
#' @return a data.frame
#'
#' @export
#'
fd_join <- function(x, y, by = NULL){
if(is.null(by)){
return(fd_bind(x,y))
} else{
stop("Not yet implemented !!!")
}
}
#' @name fd_join
#'
#' @export
#'
fd_bind <- function(x, y){
# check
length(y) == nrow(x)
colNameRef = colnames(y[[1]])
all(sapply(1:length(y), function(i) colNameRef == colnames(y[[i]])))
ncoltps = ncol(y[[1]])
# Paste:
for(c in 1:length(colNameRef)){
x[[colNameRef[c]]] = lapply(1:length(y),
function(i) y[[i]][[colNameRef[c]]])
}
return(x)
}
......@@ -15,5 +15,5 @@ fd_rbindLStoDF(ls, id = NULL)
Return a data.frame
}
\description{
Function used to filter functional data in data.frame.
Combine list of data.frame by Rows
}
......@@ -36,7 +36,6 @@ DFD
### Filter element in a column-list with `fd_filter`
```{r filter}
fd_filter(DFD, "B", 3)
```
......@@ -71,3 +70,25 @@ DFD
# apply 'fd_melt'
fd_melt(DFD, "B", "B2", keep = list("A", "C"))
```
### Join a list of data frame to a single data frame
We can bind and join a list of `data.frame`, `y`, with a single `data.frame`, `x`, when the number of row of the data.frame `x` is the same as the length of the list `y`
```{r bindDF}
#convert DFD into a list of data frame
DF = data.frame("A" = 1:5, "B" = letters[1:5])
DF
listDFD = lapply(1:nrow(DF),
function(i){
lgth = sample(5:10,1)
return(data.frame("C" = 1:lgth, "D" = letters[1:lgth]))
})
listDFD
# apply 'fd_bind'
fd_bind(DF, listDFD)
```
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment