Error In .data.frame Data Group Undefined Columns Selected
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 site About Us undefined columns selected r error Learn more about Stack Overflow the company Business Learn more about hiring developers or
Error In `[.data.frame`(frame, Predictors) : Undefined Columns Selected
posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow error in `[.data.frame`(y.data, , mediator) : undefined columns selected 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 Error in data frame undefined columns selected up
Undefined Columns Selected R Predict
vote 1 down vote favorite I've been working on an assignment where I have to read in some csv files from a directory "specdata". The files are very similar in that there are 332 titled 001.csv - 332.csv. They have consistent columns and headers, if that matters. I believe I'm close but am tripping up with the above error message " Error in [.data.frame(data1, good) : undefined columns error in data frame object not found selected" I had expected a data frame to load with all the data specified by the subset of files in id parameter. pollutantmean <- function(directory, pollutant, id = 1:332) { files <- list.files(directory) subsetFiles <- files[id] for (i in subsetFiles) { filepaths <- paste(directory,"/",i, sep='') data1 <- read.csv(filepaths) } data1 good <- complete.cases(data1) data2 <- data1[good] data2 } # test it out and ignore middle parameter for now pollutantmean("specdata", "pass", 1:3) r share|improve this question edited Oct 23 '14 at 13:29 Cerbrus 35.3k66094 asked May 14 '14 at 23:04 Doug Fir 2,732164189 add a comment| 2 Answers 2 active oldest votes up vote 5 down vote accepted Are you meaning? data2 <- data1[good,] With data1[good] you're selecting columns in a wrong way (using a logical vector of complete rows). Consider that parameter pollutant is not used; is it a column name that you want to extract? if so it should be something like data2 <- data1[good, pollutant] Furthermore consider that you have to rbind the data.frames inside the for loop, otherwise you get only the last data.frame (its completed.cases) And last but not least, i'd prefer generating filenames eg with id <- 1:322 paste0( directory, "/", gsub(" ", "0", sprintf("%3d",id)
Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ adding layers in ggplot2 (data and code included) Here is some sample data: mydata <- read.table(textConnection("Est
Error In View Undefined Columns Selected
Group Tri 0 0 4.639644
Error In Data.frame Arguments Imply Differing Number Of Rows
1 0 4.579189 2 0 4.590714 0 error in $ -.data.frame replacement has rows data has 1 4.443696 1 1 4.588243 2 1 4.650505 0 2 4.296608 http://stackoverflow.com/questions/23666611/error-in-data-frame-undefined-columns-selected 1 2 4.826036 2 2 4.765386"),header=TRUE); closeAllConnections(); I can form two plots, scatter and lines, as follows: p <- ggplot(mydata, aes(x=Est, y=Tri)) p + geom_point(aes(colour=factor(Group),shape=factor(Group))) and p+ geom_smooth(aes(group=factor(Group),color=factor(Group)),method=lm,se=F). However, I am unable to have the plots together. I obtain the following error: > p + geom_point(aes(colour=factor(Group),shape=factor(Group)))+geom_smooth(aes(group=factor(Group),color=factor(Group)),method=lm,se=F) Error in `[.data.frame`(df, , var) : undefined columns selected Thanks, Juliet ______________________________________________ http://r.789695.n4.nabble.com/adding-layers-in-ggplot2-data-and-code-included-td862717.html [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. rmailbox Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: adding layers in ggplot2 (data and code included) The way you've attempted to get this result seems to align with the way R "should" work, but it fails in this case. The fix is to break things up a little bit: p <- ggplot(mydata, aes(x=Est, y=Tri)) p <- p + geom_point(aes(colour=factor(Group),shape=factor(Group))) p <- p + geom_smooth(aes(group=factor(Group),color=factor(Group)),method=lm,se=F) p Eric Juliet Hannah wrote: > Here is some sample data: > > mydata <- read.table(textConnection("Est Group Tri > 0 0 4.639644 > 1 0 4.579189 > 2 0 4.590714 > 0 1 4.443696 > 1 1 4.588243 > 2 1 4.650505 > 0 2 4.296608 > 1 2 4.826036 > 2 2 4.765386"),header=TRUE); > closeAl
without problems.Z <-data[,c("s1_1234_m","s2_1234_m","s3_1234_m","s4_1234_m","s5_1234_m","s6_1234_m","s7_1234_m","s8_1234_m","s9_1234_m")]However, when I run the script on http://grokbase.com/t/r/r-help/12bk8jds05/r-error-in-%60-data-frame%60-undefined-columns-selected 9 different variables, it does not work:Z <-data[,c("d_s1_m","d_s2_m","d_s3_m","d_s4_m","d_s5_m","d_s6_m","d_s7_m","d_s8m","d_s9m")]Error in https://groups.google.com/d/topic/gapit-forum/akDMSzuKkQs `[.data.frame`(data, , c("d_s1_m", "d_s2_m", "d_s3_m", "d_s4_m",:undefined columns selectedThe first 9 variables are between 0 and 3, there are no missing values inthe dataset.The second 9 variables are between -3 and 3, there are no missing values error in inthe dataset.I am pretty new to R and have no idea what could cause this error.Thank you reply Tweet Search Discussions Search All Groups r-help 1 response Oldest Nested David Winsemius You have probably misspelled one or more the column names. For instance I suspect that undefined columns selected one or both of these might be lacking a second "_" : "d_s8m","d_s9m" If you feel thsi is wrong then you at the very least need to offer str(data) BTW, data is the name of a perfectly good function, so naming your dataframe "data" is likely to create confusion. -- David. David Winsemius, MD Alameda, CA, USA David Winsemius at Nov 19, 2012 at 5:23 am ⇧ On Nov 18, 2012, at 6:34 PM, Eiko Fried wrote:When I run this script on 9 variables, it works without problems.Z <-data[,c("s1_1234_m","s2_1234_m","s3_1234_m","s4_1234_m","s5_1234_m","s6_1234_m","s7_1234_m","s8_1234_m","s9_1234_m")]However, when I run the script on 9 different variables, it does notwork:Z <-data[,c("d_s1_m","d_s2_m","d_s3_m","d_s4_m","d_s5_m","d_s6_m","d_s7_m","d_s8m","d_s9m")]Error in `[.data.frame`(data, , c("d_s1_m", "d_s2_m", "d_s3_m","d_s4_m",:undefined columns selectedYou have probably misspelled one or more the column names. Forinstance I suspect that one or both of these might be lacking a second"_" : "d_s8m",
från GoogleLogga inDolda fältSök efter grupper eller meddelanden