(1)我有一个大表在R中读取,有超过10000的行和10列。
(2)表的第3栏包含医院的名称。其中一些是重复的,甚至更多。
(3)我有一个医院名称的向量,例如,其中10个还需要进一步研究。
(4)您是否介意教我如何使用步骤3中列出的名称提取step1中的所有行?
下面是我的输入文件的一个简短示例;
Patients Treatment Hospital Response
1 A YYY Good
2 B YYY Dead
3 A ZZZ Good
4 A
我最近发现,在用"[“将对象(即数据框架)添加之后,结果对象可以是同一行代码上的"[”子集(我应该更早地实现它!)。下面是一个示例:
# Create a data frame
df1 <- as.data.frame(matrix(1:9, nrow = 3))
# Take a look at the data frame
df1
V1 V2 V3
1 1 4 7
2 2 5 8
3 3 6 9
# If I want the value which is on the 3rd row and 2nd column
df1[3,2]
[1]
我有这样一个数据框架(Df):
col1 col2
a 2
a 3
b 7
b 5
c 4
c 2
c 1
d 5
d 7
即;
df<-data.frame(col1=c("a","a","b","b","c","c","c","d","d"), col2=c(2,3,7,5,4,2,1,5,7))
期望的输出数据帧(Df1)是:
col1 col2
b
给出如下数据:
city type count
0 bj a 10
1 bj a 23
2 bj b 12
3 bj c 34
4 sh a 17
5 sh b 18
6 sh c 25
7 sh c 13
8 sh a 12
我想根据city和type:bj-a, bj-c, sh-b过滤行,预期的结果如下:
city type count
0 bj a 10
1 bj a 23
2
我有这样的数据,其中一些“名称”出现了三次以上:
df <- data.frame(name = c("a", "a", "a", "b", "b", "c", "c", "c", "c"), x = 1:9)
name x
1 a 1
2 a 2
3 a 3
4 b 4
5 b 5
6 c 6
7 c 7
8 c 8
9 c 9
我希望根据name变量每个级别中的行数(观察)对数据进行