140,139,129,135,121,109,150),
英语=c(111,123,141,101,99,130,140),
综合=c(125,115,119,130,121,113,130)
)
3.1 R方法...3.2 R语言tidyr包函数:gather,spread
library(tidyr)
short2long = gather(data,key=科目,value=成绩, 语文:综合)
long2short...= spread(short2long,key=科目,value=成绩)
3.3 SQL方法
# 宽变长
short2long = sqldf("
select 班级, 姓名, '语文' as 科目..., 语文 as 成绩 from data
union all
select 班级, 姓名, '数学' as 科目, 数学 as 成绩 from data
union all
select 班级,...long2short = sqldf("
select
班级,姓名,
max(case 科目 when '语文' then 成绩 else 0 end) as 语文,
max(case 科目 when