I have a piece of code that works fine outside the function but not inside the function(R programming language).
I am reading an Excel file with:
myFile = read.csv2("myFile.csv", na.strings = c("-", "k.A"))
There are a number of columns in this file like gender(Geschlecht), grades, semesters etc...
I then run the following code which gives me the bar plot for the gender column.
barplot(prop.table(table(myFile$Geschlecht)))
I want to make a function that I can use to print a barplot for any column, as long as I know the name of the column heading.
This is the function I made:
mybarplot = function(dataCat, Title){
barplot(prop.table(table(myFile$dataCat)))
}
I then call the function like this:
mybarplot(Geschlecht,"Geschlecht")
This gives me the following error and warnings:
*Error in plot.window(xlim, ylim, log = log, ...) :
need finite 'xlim' values
In addition: Warning messages:
1: In min(w.l) : no non-missing arguments to min; returning Inf
2: In max(w.r) : no non-missing arguments to max; returning -Inf
3: In min(x) : no non-missing arguments to min; returning Inf
4: In max(x) :
Show Traceback
Rerun with Debug
Error in plot.window(xlim, ylim, log = log, ...) :
need finite 'xlim' values*
As far as I can see, this has something to do with the NA values in my file? These values are specified by k.A or - in my Excel file(German language in case you are wondering).
I would appreciate if someone can point me in the right direction so I can take care of this as i'm stuck on this since day before yesterday.