Error In .data.frame Y Yok Undefined Columns Selected
in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ suggestion for paired t-tests There's a funny inconsistency in how t.test handles paired=T or paired=F. If x and y parameters are lists, paired=F works, but paired=T doesn't. > lg=read.csv("my.csv") > a = subset(lg, condition=="a")["score"] > b = subset(lg, condition=="b")["score"] > t.test(a,b) > t.test(a,b, paired=TRUE) Error in `[.data.frame`(y, yok) : undefined columns selected But this works > a=a[,1] > b=b[,1] > t.test(a,b, paired=TRUE) ... ______________________________________________ [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. Juliet Hannah Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: suggestion for paired t-tests Hi Jack, Maybe this helps. # make some data set.seed(123) condition <- factor(rep(c("a","b"), each = 5)) score <- rnorm(10); lg <- data.frame(condition, score) # Carry out commands a <- subset(lg,condition=="a")["score"] b <- subset(lg,condition=="b")["score"] t.test(a,b,paired=TRUE) #Error in `[.data.frame`(y, yok) : undefined columns selected # a and b are still data frames #So this works. We must refer to score, which is being compared. t.test(a$score,b$score,paired=TRUE) a=a[,1] b=b[,1] # This now works because a and b are vectors # so we don't need $ to access score t.test(a,b, paired=TRUE) Regards, Juliet ______________________________________________ [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. Ben Bolker Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ ♦ Re: suggestion for paired t-tests In reply to this post by Jack Tanner jacktanner wrote There's a funny inconsistency in how t.test handles paired=T or paired=F. If x and y parameters are lists, paired=F works, but paired=T doesn't. > lg=read.csv("my.csv") > a = subset(lg, condition=="a")["score"] > b = subset(lg, condition=="b")["score"] > t.test(a,b) > t.test(a,b, paired=TRUE) Error in `[.data.frame`(y, yok) : undefined columns selected But this works > a=a[,1] > b=b[,1] > t.test(a,b, paired=TRUE) ... It's sort of an accident that th
] [ subject ] [ author ] Le dimanche 29 janvier 2012 à 21:50 -0500, xiaocong zuo a écrit : > Hi,all, > > when I run the below code,there is an error http://r.789695.n4.nabble.com/suggestion-for-paired-t-tests-td897763.html occured. could you please tell > me how to treat it? > > pdf('covariate.pdf') > > par(mfrow=c(1,1)) > > pairs(data2[,c("ID","TYPE","AGE","GNDR","HT")], > + panel=function(x,y) { points(x,y); lines(lowess(x,y))}) > Error in `[.data.frame`(data2, , c("ID", "TYPE", "AGE", https://stat.ethz.ch/pipermail/r-help/2012-January/301956.html "GNDR", "HT")) : > undefined columns selected > > dev.off() > RStudioGD > 2 > Thank you very much! This simply means that one of the columns you tried to select doesn't exist in data2. You can see what columns are present using: colnames(data2) or since data2 is a data frame: names(data2) But you could probably have figured this out by yourself... ;-) Hope this helps Previous message: [R] about "undefined columns selected" Next message: [R] Data generation Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] More information about the R-help mailing list
rnorm(10); lg http://qiita.com/mwmsnn/items/1c6c03f06bd8be93230c <- data.frame(condition, score) # Carry out commands a <- subset(lg,condition=="a")["score"] b <- subset(lg,condition=="b")["score"] t.test(a,b,paired=TRUE) #Error in `[.data.frame`(y, yok) : undefined columns selected # a and b are error in still data frames #So this works. We must refer to score, which is being compared. t.test(a$score,b$score,paired=TRUE) a=a[,1] b=b[,1] # This now works because a and b are vectors # so we don't need error in .data.frame $ to access score t.test(a,b, paired=TRUE) Regards, Juliet ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Previous message View by thread View by date Next message [R] suggestion for paired t-tests Jack Tanner Re: [R] suggestion for paired t-tests Juliet Hannah Re: [R] suggestion for paired t-tests Ben Bolker Reply via email to Search the site The Mail Archive home r-help - all messages r-help - about the list Expand Previous message Next message The Mail Archive home Add your mailing list FAQ Support Privacy 93d6f2a80907250801i3db43fb2r4bd0d18dc4555f99@mail.gmail.com
攻撃的または迷惑な内容を含んでいます 不適切な内容を含んでいます 送信88ストック5コメントストックストック済み解除 この記事は最終更新日から1年以上が経過しています。知っていると便利かもしれない小技から,どーでもいい小技まで.ググったサンプルをコピペして完了!系大学院生が読むと,何か新しい発見があるかもしれません.使わなさ(当社比)を4段階(☆☆☆,★☆☆,★★☆,★★★)で表記しますので,ああ確かに知らなくていいなって思ってください.新しい技を仕入れ次第,更新します. 多次元データへのアクセス 次元を落とさない 使わなさ:☆☆☆(そこそこ役に立つ) デフォルト設定では,行列や配列の一部分にアクセスした場合,その戻り値はできる限り次元を落としたものになります(次元を落とすことを「ドロップする」と言うことにします).データフレームでも同様です. > x <- array(1:1000, c(10, 10, 10)) > class(x[1, 1, 1]) # 3次元配列 → 要素数1のベクトル(スカラ) [1] "integer" > class(x[1, 1, ]) # 3次元配列 → ベクトル [1] "integer" > class(x[1, , ]) # 3次元配列 → 行列 [1] "matrix" 引数 drop に FALSE を指定することで,次元を維持できます. > class(x[1, 1, 1, drop=F]) [1] "array" > class(x[1, 1, , drop=F]) [1] "array" > class(x[1, , , drop=F]) [1] "array" これは,行列から条件を満たす部分を取り出して処理したい場合に役立ちます. index <- which(x[ , 1] != 0); x.sub <- x[index, -1, drop=F]; apply(x.sub, 1, sum); この例では index の要素数が1になる可能性があり,その場合 x[index, -1] は行列ではなくベクトルになります.しかし,関数 apply はベクトルに対して適用できないので,このままではエラーになります.そこで drop=F を指定し,常に行列と