简体   繁体   English

如何通过使用R中的第一列值访问数据帧中的行

[英]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.

相关问题 如何循环R中两列数据框中的行值? - How to loop over row values in a two column data frame in R? 当列数据使用 R 重复时如何访问数据框中的值? - How to access values in data frame when column data repeats itself using R? 如何转置数据框,使用R保留行和列名称 - How to transpose data frame , keeping row and column names using R R中数据帧行中第一组连续值的返回列索引 - Return column index of first set of consecutive values in data frame row in R 在 R 中,逐行迭代 data.frame 并访问列值 - In R, iterate over a data.frame by row and get access to the column values R as.data.frame.matrix将第一列变成行名 - R as.data.frame.matrix turns first column into row names 将列名转换为 R 中数据框的第一行 - Convert Column names into first row of Data frame in R 如何在R中的数据帧中找到一列中出现字符串最长的时间以及另一列中对应的第一个和最后一个值? - How to find the longest occurrence of a string in a column and corresponding first and last values from another column in a data frame in R? R:如何将数据帧除以列值? - R: How to divide a data frame by column values? 如何提取数据帧的每一行并将解析的字符串从另一个数据帧添加到R中第一个数据帧的列 - how to extract each row of a dataframe and add the parsed strings from another dataframe to a column of the first data frame in R
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM