r - How to delete specific rows from multiple columns -
i importing columns multiple csv files r. want delete data after row 1472.
temp = list.files(pattern="*.csv") #importing csv files normalyears<-c(temp[1],temp[2],temp[3],temp[5],temp[6],temp[7],temp[9],temp[10],temp[11],temp[13],temp[14],temp[15],temp[17],temp[18],temp[19],temp[21],temp[22],temp[23]) leapyears<-c(temp[4],temp[8],temp[12],temp[16],temp[20]) #separating csv files based on leap years , normal years. importing second column of each csv file. myfiles_normalyears = lapply(normalyears, read.delim,colclasses=c('null','numeric'),sep =",") myfiles_leapyears = lapply(leapyears, read.delim,colclasses=c('null','numeric'),sep =",") new.data.leapyears <- null for(i in 1:length(myfiles_leapyears)) { in.data <- read.table(if(is.null(myfiles_leapyears[i])),skip=c(1472:4399),sep=",") new.data.leapyears <- rbind(new.data.leapyears, in.data)}
the loop suppose delete rows starting 1472 4399.
error: error in read.table(myfiles_leapyears[i], skip = c(1472:4399), sep = ",") :
'file' must character string or connection
your myfiles_leapyears
list
. when subsetting list, need double brackets access single element, otherwise sublist of length 1.
so replace
myfiles_leapyears[i]
with
myfiles_leapyears[[i]]
that @ least take care of invalid subscript type 'list'
errors. i'd second josh w. nrows
argument seems smarter skip
argument.
alternatively, if define using sapply
("s" simplify) instead of lapply
("l" list), you'll fine using [i]
:
myfiles_leapyears = lapply(leapyears, read.delim,colclasses=c('null','numeric'),sep =",")
Comments
Post a Comment