If I have two tables (File1) and (File2)
> dput(File1)
structure(list(Column.1 = structure(1:3, .Label = c("Row 1",
"Row 2", "Row 3"), class = "factor"), Column.2 = c(NA, NA, NA
), Column.3 = c(NA, NA, NA), colNames = c(TRUE, TRUE, TRUE)), class = "data.frame", row.names = c(NA,
-3L))
> dput(File2)
structure(list(Column.1 = structure(1:3, .Label = c("Row 1",
"Row 2", "Row 3"), class = "factor"), Column.2 = c(1, 2, 34),
Column.3 = c(NA, NA, NA), colNames = c(TRUE, TRUE, TRUE)), class = "data.frame", row.names = c(NA,
-3L))
and I want to confirm that the Column Names, Column Types, and Number of Rows and Columns between File 1 and File 2, returning a TRUE if they are all the same and a FALSE if not, how can I add on to this code that I have written?
I tried some of the answers in Compare column types between two data frames, but I am only looking for a TRUE or FALSE answer. Here's my current code.
check_file <- function(File1 , File2) {
if (!nrow(File1) == nrow(File2)) {
print("Non matching number of rows")
return(FALSE)
} else if (!ncol(File1) == ncol(File2)) {
print("non matching number of columns")
return(FALSE)
} else if (length(grep("FALSE", names(File1) == names(File2)))>0){
print("Non matching names of columns")
return(FALSE)
}else if (!class(File1)==class(File2)){
print("Non matching column types")
}
return(TRUE)
}
check <- check_file(File1, File2)
if (check) {
return(TRUE)
} else{
return(FALSE)
}
I think all that´s left is the types. For example, in the dput File 2 Column 2 has numbers while File 1 has NA. They don´t have to be the same numbers, but it needs to return false since it´s NA. If File 1 had 3,2,564, it should return TRUE.