[英]How to access a row in a data frame by using first column values in R
intercatedData n
1 Completed Degree in 2 Years.0 2
2 Retained to Midyear Year 2.0 1
3 Retained to Start of Year 2.0 1
4 Retained to Midyear Year 2.1 1
5 Retained to Start of Year 2.1 1
Here is the data frame(mydf)
that i am using. 这是我正在使用的数据frame(mydf)
。
Now i want access first row value (that is 2
) by its name ( Completed Degree in 2 Years.0
). 现在我想访问第一行的值(即2
)通过其名称( Completed Degree in 2 Years.0
)。 I am able to access the value by using print(mydf$n[1])
but right I would like to access the value by name instead of by index 1
. 我可以使用print(mydf$n[1])
访问该值,但是我想按名称而不是按索引1
访问该值。
How can I access the value by name instead of by index ? 如何通过名称而不是通过索引访问值?
mydf[ mydf$intercatedData == 'Completed Degree in 2 Years.0', ]
A DATA record in a dataframe has a row AND column and so can be referred as so 数据框中的DATA记录具有行AND列,因此可以称为
mydf[2,3]
will give me record in 2nd row and 3rd column for dataframe named mydf mydf[2,3]
将在名为mydf的数据帧的第二行和第三列中给我记录
mydf[2,]
will give me record in 2nd row and all columns for that for dataframe named mydf mydf[2,]
将给我第二行的记录,以及所有列的数据框,名为mydf
mydf[,3]
will give me records in 3rd column for dataframe named mydf mydf[,3]
将在第三列中为名为mydf的数据框提供记录
This dataframe property can now be used for conditional selection 现在可以将此数据框属性用于条件选择
mydf[ mydf$intercatedData == 'Completed Degree in 2 Years.0', ]
Says give me all rows where the value for mydf$intercatedData is 'Completed Degree in 2 Years.0' and all columns 说给我所有行,其中mydf $ intercatedData的值是“ 2 Years.0中的完成学位”,并且所有列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.