An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111116/6cdb385d/attachment.pl>
how to indice the column in the data.frame
4 messages · haohao Tsing, Joshua Wiley, Sarah Goslee +1 more
Hi, Look at ?"[" anadata <- newdata[, cmn] ## i.e., extract all rows (the first argument is empty of the 2 column anadata <- newdata[, 2] Hope this helps, Josh
On Tue, Nov 15, 2011 at 8:02 AM, haohao Tsing <haohaorain at gmail.com> wrote:
hi R,users
?Now I read a data from a txt file
newdata<-read.table("1.txt")
in the 1.txt ,there are several column shown as below
1 3 4 5
2 3 5 6
4 5 6 7
so when I want analysis the second column
anadata<-newdata$V2
but my question I can not use some certain variable to indice the column?
e.g
cmn=2
anadata<-newdata$Vcmn
how can I finish this command ?can anyone help me ? thank yo .
? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at 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.
Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/
On Tue, Nov 15, 2011 at 11:23 AM, Joshua Wiley <jwiley.psych at gmail.com> wrote:
Hi, Look at ?"[" anadata <- newdata[, cmn] ## i.e., extract all rows (the first argument is empty of the 2 column anadata <- newdata[, 2]
Or, if this is part of a more general problem and the column names are not necessarily in sequence:
newdata <- data.frame(V1=1:3, V2=4:6, V3=7:9)
newdata[, paste("V", 2, sep="")]
[1] 4 5 6 Sarah
Hope this helps, Josh On Tue, Nov 15, 2011 at 8:02 AM, haohao Tsing <haohaorain at gmail.com> wrote:
hi R,users
?Now I read a data from a txt file
newdata<-read.table("1.txt")
in the 1.txt ,there are several column shown as below
1 3 4 5
2 3 5 6
4 5 6 7
so when I want analysis the second column
anadata<-newdata$V2
but my question I can not use some certain variable to indice the column?
e.g
cmn=2
anadata<-newdata$Vcmn
how can I finish this command ?can anyone help me ? thank yo .
Sarah Goslee http://www.functionaldiversity.org
On Nov 15, 2011, at 11:02 AM, haohao Tsing wrote:
hi R,users
Now I read a data from a txt file
newdata<-read.table("1.txt")
in the 1.txt ,there are several column shown as below
1 3 4 5
2 3 5 6
4 5 6 7
so when I want analysis the second column
anadata<-newdata$V2
but my question I can not use some certain variable to indice the
column?
e.g
cmn=2
anadata<-newdata$Vcmn
Either:
anadata<-newdata[[ paste("V", cmn, sep="") ]]
Or:
anadata<-newdata[[cmn]]
how can I finish this command ?can anyone help me ? thank yo .
Your should go back and study your introductory manual now. If this is not near the begininning of that manual, you hsoulswitch manuals. You should also type: ?"$" And read that page carefully and try all of the examples. It will probably take more than one reading to master its contents, but it is a core part of learning R.
David Winsemius, MD West Hartford, CT