假设我有这样的数据框:
family relationship meanings edu
1 1 A respondent 12
2 1 B respondent's spouse 18
3 1 C A's father 10
4 1 D A's mother 9
5 1 E1 A's first son 15
6 1 F1 E1's spouse 14
7 1 G11 E1's first son 3
8 1 G12 E1's second son 1
9 1 E2 A's second son 13
10 2 A respondent 21
11 2 B respondent's spouse 16
12 2 C A's father 12
13 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将数据集导入到RStudio,但是我遇到了汉字,因为它们变成了乱码.这是代码:
library(tidyverse)
df <- read_csv("??,??\n??,??")
df
# A tibble: 1 x 2
`\xd6\xd0\xce\xc4` `?\xce\xc4`
<chr> <chr>
1 "<U+04E2>\xce\xc4" "<U+00B5>\xc2\xce\xc4"
Run Code Online (Sandbox Code Playgroud)
当我使用基函数read.csv时,它运行良好.我想我必须对编码做错事.但是read_csv中没有编码选项,我该怎么做?
假设我有一个像这样的data.frame:
dt=data.frame(id=rep(letters[1:3],each=4),
year=rep(1:4,3),
invest=1:12,
y=rep(c(1,0,0,0),3))
dt
id year invest y
1 a 1 1 1
2 a 2 2 0
3 a 3 3 0
4 a 4 4 0
5 b 1 5 1
6 b 2 6 0
7 b 3 7 0
8 b 4 8 0
9 c 1 9 1
10 c 2 10 0
11 c 3 11 0
12 c 4 12 0
Run Code Online (Sandbox Code Playgroud)
我想得到一个新的列y2:y2 = lag.y2*0.8 + invest,第一年的y2等于y.像这样:
id year invest y y2 …
Run Code Online (Sandbox Code Playgroud)