我的数据框架如下:
b <- data.frame(height = c(190,165,174,176), name = c('John Smith 34','Mr.Turner 54', 'Antonio P. 23', 'John Brown 31'))
# height name
# 1 190 John Smith 34
# 2 165 Mr.Turner 54
# 3 174 Antonio P. 23
# 4 176 John Brown 31
Run Code Online (Sandbox Code Playgroud)
我们可以看到名称和年龄是相同的值.所以我想用字符串中的最后两个字符拆分它:
height name age
1 190 John Smith 34
2 165 Mr.Turner 54
3 174 Antonio P. 23
4 176 John Brown 31
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做?
我有一个大的data.frame.data.frame包含很多值.
例如:
df <- data.frame(Company = c('A', 'A', 'B', 'C', 'A', 'B', 'B', 'C', 'C'),
Name = c("Wayne", "Duane", "William", "Rafael", "John", "Eric", "James", "Pablo", "Tammy"),
Age = c(26, 27, 28, 32, 28, 24, 34, 30, 25),
Wages = c(50000, 70000, 70000, 60000, 50000, 70000, 65000, 50000, 50000),
Education.University = c(1, 1, 1, 0, 0, 1, 1, 0, 1),
Productivity = c(100, 120, 120, 95, 88, 115, 100, 90, 120))
Run Code Online (Sandbox Code Playgroud)
我如何汇总我的data.frame?我想分析每家公司的价值观.它必须看起来像:
年龄 - >公司所有员工的平均年龄
工资 - >公司所有员工的平均工资
Education.University …
我要选择Max Price的TOP 2产品.
ProductID ProductName SupplierID CategoryID Unit Price
1 Chais 1 1 10 bags 18
2 Chang 1 1 24 bottles 19
3 Aniseed Syrup 1 2 12 bottles 10
Run Code Online (Sandbox Code Playgroud)
我用过:
Select TOP 2 *
from Products
where Price = (Select Max(Price) from Products);
Run Code Online (Sandbox Code Playgroud)
但结果只有一排.