--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I guess the "data" variable" contains the name of the file, and hence has not dimension.or did I miss something?
Thanks Amit!!
On Tue, Jul 1, 2014 at 6:15 PM, Ayala Allon <ayala...@gmail.com> wrote:
Hi,I'm trying to write a function that computes the mean for the second or third columns in a csv file. When I run the function I get the next error for data.column <- data[,2] or data.column <- data[,3] : incorrect number of dimensions error. However when I load the csv file and run these lines outside of the function I don't get an error. I can't figure out what am I missing.This is the function:pollutantmean<- function(directory,pollutant,id) {setwd(directory)if (id < 9) {data<- paste("00", id, ".csv", sep = "")}else if (id > 10 && id < 100) {data<- paste("0", id, ".csv", sep = "")}read.csv(data)if (pollutant == "sulfate") {data.column <- data[,2] ###### this is the line for which I get the error} else if (pollutant == "nitrate") {data.column <- data[,3] ###### this is the line for which I get the error}bad <- is.na(data.column)x <- mean(data.column[!bad])#x <- mean(good)list(directory = getwd(), head.data = head(data), mean.column=x)}Any help will be greatly appreciated,Ayala
--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.