简体   繁体   English

根据 R 中的列值,基于现有 dataframe 创建另一个 dataframe

[英]Create another dataframe based on an existing dataframe based on a column value in R

I have the following data frame, df in R:我有以下数据框,R 中的 df:

ID    Name    Class
3     John    3A
32    Fanny   7B
12    Greg    3A

and I want to segregate the data, by creating a new dataframe for all rows with Class value 3A which means the new dataframe would be:我想通过为 Class 值为 3A 的所有行创建一个新的 dataframe 来分离数据,这意味着新的 dataframe 将是:

ID    Name    Class
3     John    3A
12    Greg    3A

Since rows above have value 3A in the Class column.由于上面的行在 Class 列中的值为 3A。

I tried the following:我尝试了以下方法:

df_2 <- df[df["Class"]=="3A"]

But the df_2 dataframe does not seem to appear.但是df_2 dataframe似乎没有出现。

You are confusing the python and R您混淆了 python 和 R

Here is the correct code:这是正确的代码:

df_2 <- df[df$Class=="3A", ]
df_2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM