I've been trying to create a function that extracts the unique values of a given column in a given data frame, by writing this code:
val_uniques <- function(colname, datframe)
if colname %in% colnames(dataframe) {
print(unique(dataframe[, colname], incomparables = FALSE))
} else {
print("cette colonne n'existe pas")
}
but unfortunately, I keep getting this error :
print( unique(dataframe[,colname] , incomparables = FALSE))} else { print("cette colonne n'existe pas")} Error: unexpected '}' in "print( unique(dataframe[,colname] , incomparables = FALSE))}"
I know it's a dumb question because it has something to do with }
in if
or else
, but I've tried everything and it didn't work.
P.S. It's my first programming stuff in R.
There are some typos in object names
datframe
anddataframe
as well as curly brackets are misplaced: