Error In Attributesout - Attributescol
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this error in names(ret2) <- rowns : site About Us Learn more about Stack Overflow the company Business Learn more error in `colnames<-`(`*tmp*`, value = c( about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss "loop_apply" not resolved from current namespace (plyr) Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up ddply error: Error
Ddply
in attributes(out) <- attributes(col) : 'names' attribute must be the same length as the vector up vote 1 down vote favorite 1 I am trying to apply ddply on a large data.frame (38000 rows / 10 variables), but I am stuck with an error: ddply(uncertainty.long, .(Species), "nrow") returns the error: Error in attributes(out) <- attributes(col) : 'names' attribute [38000] must be the same length $ operator is invalid for atomic vectors as the vector [3800] > traceback() 11: FUN(1:10[[5L]], ...) 10: lapply(seq_len(n), extract_col_rows, df = x, i = i) 9: extract_rows(x$data, x$index[[i]]) 8: `[[.indexed_df`(pieces, i) 7: pieces[[i]] 6: (function (i) { piece <- pieces[[i]] if (.inform) { res <- try(.fun(piece, ...)) if (inherits(res, "try-error")) { piece <- paste(capture.output(print(piece)), collapse = "\n") stop("with piece ", i, ": \n", piece, call. = FALSE) } } else { res <- .fun(piece, ...) } progress$step() res })(1L) 5: .Call("loop_apply", as.integer(n), f, env) 4: loop_apply(n, do.ply) 3: llply(.data = .data, .fun = .fun, ..., .progress = .progress, .inform = .inform, .parallel = .parallel, .paropts = .paropts) 2: ldply(.data = pieces, .fun = .fun, ..., .progress = .progress, .inform = .inform, .parallel = .parallel, .paropts = .paropts) 1: ddply(uncertainty.long, .(Species), "nrow") Some more details about my data.frame: > head(uncertainty.long) Stack Variable PARun Model Species value year scenario GCM sp 1 sync_current Total PA1 GLM Arctosafulvolineata 100.0000 NA
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up ddply - common mistake when error “'names' attribute [] must be the same length as the vector []” occurs? up vote 0 down vote favorite I know that there is a few threads (1, 2) already about it and I have read them, but I still do not find my http://stackoverflow.com/questions/18854934/ddply-error-error-in-attributesout-attributescol-names-attribute-mus problem. The error seems to occur "randomly", even though I am sure it is not, but I can just not figure out, when. Therefore I cannot really provide a minimal example, as I could not find a "pattern" yet. But basically I always use hourly <- ddply(set, c("Date", "Hour"), summarise, avg = mean(Value)) which leads to Error: 'names' attribute [11] must be the same length as the vector [1] traceback() provides > traceback() 6: stop(list(message = "Attribut 'names' [11] muss dieselbe Länge haben wie der Vektor [1]", call = http://stackoverflow.com/questions/26408425/ddply-common-mistake-when-error-names-attribute-must-be-the-same-length NULL, cppstack = NULL)) 5: .Call("plyr_loop_apply", PACKAGE = "plyr", n, f) 4: loop_apply(n, do.ply) 3: llply(.data = .data, .fun = .fun, ..., .progress = .progress, .inform = .inform, .parallel = .parallel, .paropts = .paropts) 2: ldply(.data = pieces, .fun = .fun, ..., .progress = .progress, .inform = .inform, .parallel = .parallel, .paropts = .paropts) 1: ddply(set, c("Date", "Hour"), summarise, avg = mean(Value)) The str() of the dataframe: > str(set) 'data.frame': 2155 obs. of 16 variables: $ T_Stamp : POSIXlt, format: "2013-06-18 09:01:00" "2013-06-18 09:02:00" "2013-06-18 09:03:00" ... $ Date : Date, format: "2013-06-18" "2013-06-18" "2013-06-18" ... $ Time : num 0.376 0.376 0.377 0.378 0.378 ... $ Year : int 2013 2013 2013 2013 2013 2013 2013 2013 2013 2013 ... $ Month : int 6 6 6 6 6 6 6 6 6 6 ... $ Day : int 18 18 18 18 18 18 18 18 18 18 ... $ Hour : int 9 9 9 9 9 9 9 9 9 9 ... $ Min : int 1 2 3 4 5 6 7 8 9 10 ... $ Customer: chr "1" "1" "1" "1" ... $ Property: chr "1" "1" "1" "1" ... $ Serial : Factor w/ 13 levels "000D6F00010B723F",..: 9 9 9 9 9 9 9 9 9 9 ... $ Sensor : chr "AirCon" "AirCon" "AirCon" "AirCon" ... $ ID : Factor w/ 44 levels "300","301","302",..: 30 30 30 30 30 30 30 30 30 30 ... $ Unit : chr "Total Active Power" "Total Active Power" "Total Active Power" "Total Active Power" ... $ Valu
Sign in Pricing Blog Support Search GitHub This repository Watch 55 Star 446 Fork 112 hadley/plyr Code Issues 17 Pull requests 3 Projects 0 Pulse Graphs New https://github.com/hadley/plyr/issues/132 issue R exception when data frame has strptime output #132 Closed jpritikin opened this Issue Jan 28, 2013 · 4 comments Projects None yet Labels None yet Milestone No http://r.789695.n4.nabble.com/Error-in-names-x-lt-value-names-attribute-must-be-the-same-length-as-the-vector-td4629998.html milestone Assignees No one assigned 4 participants jpritikin commented Jan 28, 2013 Error in attributes(out) <- attributes(col) : 'names' attribute [9] must be the same length as the vector [1] Reproduce error in with: � df <- expand.grid(factor(1:5)) dates <- c("02/27/92", "02/27/92", "01/14/92", "02/28/92", "02/01/92") times <- c("23:03:20", "22:29:56", "01:03:30", "18:21:03", "16:56:26") df$tm <- strptime(paste(dates, times), "%m/%d/%y %H:%M:%S") attributes(df$tm) ddply(df, ~Var1, dim) BrianDiggs commented Jan 28, 2013 In general, POSIXlt objects cause problems when included in data frames. From the DateTimeClasses help page "POSIXct" is more convenient for including in data frames, and "POSIXlt" is closer error in attributesout to human-readable forms. Changing to that makes it work df$tm <- as.POSIXct(strptime(paste(dates, times), "%m/%d/%y %H:%M:%S")) ddply(df, ~Var1, dim) yields > ddply(df, ~Var1, dim) Var1 V1 V2 1 1 1 2 2 2 1 2 3 3 1 2 4 4 1 2 5 5 1 2 jpritikin commented Jan 29, 2013 Sure, but the error message could be better. At least wrap the code with a tryCatch and stop with the column name so I would have known where to look. Owner hadley commented Jan 2, 2014 This is difficult to catch automatically unfortunately. hadley closed this Jan 2, 2014 dioh commented Jun 5, 2015 Hi all, I have the same problems but no date values. Any clues? Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment Contact GitHub API Training Shop Blog About © 2016 GitHub, Inc. Terms Privacy Security Status Help You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
3 messages Priya Bhatt Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Error in names(x) <- value: 'names' attribute must be the same length as the vector Dear R-helpers, I am stuck on an error in R: When I run my code (below), I get this error back: Error in names(x) <- value : 'names' attribute must be the same length as the vector Then when I use traceback(), R gives me back this in return: `colnames<-`(`*tmp*`, value = c(""Item", "Color" ,"Number", "Size")) I'm not exactly sure how to fix this problem. Any advice would be greatly appreciated! Thanks, Priya MODIFIED CODE: # Looping through a series of CSV files for (c in csvfiles) { #A DF (prevdf) was created based on an initial csv file.. #so the condition below states that if there are rows with NAs or the number of rows in prevdf is zero if( (apply(prevdf, 1, function(y) !sum(!is.na(y))==1) > 0) || (nrow(prevdf) == 0) ) { #Open a new file currentCSVFile <- read.csv(c, header=TRUE) #pick only the few columns we want from the file currentCSVFile <- data.frame(currentCSVFile$Item, currentCSVFile$Color..type , currentCSVFile$Number..owned, currentCSVFile$Size..shirt) #rename the column names colnames(currentCSVFile) <- c("Item", "Color" ,"Number", "Size") #find the rows in prevdf that do not have any values. (sum should be 1 because the Item name is unique for every row) NArows <- prevdf[apply(prevdf, 1, function(y) sum(!is.na(y))==1),] #if NAs rows is not equal to zero if (nrow(NArows) != 0 ) { #find the rows in the current CSV file where there is missing data in prevdf (this info is in NArows) intersectItem<- intersect(currentCSVFile$Item, NArows$Item) #initiate another data frame to put the data in newdf.int <- data.frame(Item=c(), Color=c(), Number=c(), Size=c()) print(nrow(currentCSVFile)) for (i in 1:nrow(currentCSVFile)) { print("In loop") # check for me row <- currentCSVFile[i,] if (row$Item %in% intersectItem){ # this is where the code stops and throws back error . . . # do