2382 10

[问答] 数据框的一个小问题,望解答 [推广有奖]

  • 0关注
  • 0粉丝

本科生

99%

还不是VIP/贵宾

-

威望
0
论坛币
92 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
186 点
帖子
61
精华
0
在线时间
51 小时
注册时间
2013-4-22
最后登录
2015-8-3

楼主
红与黑的铭记 发表于 2013-11-6 20:26:33 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
> x
      地区 人均GDP..元. 进出口总额.万美元. 固定资产投资..亿元.
1   北  京        50467          7046046.7              3296.4
2   天  津        41163          6728322.5              1820.5
3   河  北        16962          2347705.7              5470.2
4   山  西        14123           966156.9              2255.7
5   内蒙古        20053           611285.8              3363.2
6   辽  宁        21788          5242343.3              5689.6
7   吉  林        15720           870143.9              2594.3
8   黑龙江        16195          1407242.6              2236.0
9   上  海        57695         22123269.5              3900.0
10  江  苏        28814         29904118.2             10069.2
11  浙  江        31874         16007542.3              7590.2
12  安  徽        10055          1225027.0              3533.6
13  福  建        21471          6488832.4              2981.8
14  江  西        10798           725200.5              2683.6
15  山  东        23794         11063558.6             11111.4
16  河  南        13313          1098215.3              5904.7
17  湖  北        13296          1211324.5              3343.5
18  湖  南        11950           797849.2              3175.5
19  广  东        28332         54182987.6              7973.4
20  广  西        10296           760971.0              2198.7
21  海  南        12654           339237.3               423.9
22  重  庆        12457           531063.6              2407.4
23  四  川        10546          1067279.9              4412.9
24  贵  州         5787           221258.2              1197.4
25  云  南         8970           637717.2              2208.6
26  西  藏        10430            22714.4               231.1
27  陕  西        12138           692238.9              2480.7
28  甘  肃         8757           443968.5              1022.6
29  青  海        11762            93667.3               408.5
30  宁  夏        11847           161269.5               498.7
31  新  疆        15000          1021088.8              1567.1
   社会消费品零售总额..亿元. 年末总人口..万人. 进
1                     3275.2              1581  1
2                     1356.8              1075  1
3                     3397.4              6898  1
4                     1613.4              3375  1
5                     1595.3              2397  1
6                     3434.6              4271  1
7                     1675.8              2723  1
8                     1997.7              3823  1
9                     3360.4              1815  1
10                    6623.2              7550  1
11                    5325.3              4980  1
12                    2029.4              6110  1
13                    2704.2              3558  1
14                    1428.0              4339  1
15                    7122.5              9309  1
16                    3880.5              9392  1
17                    3412.0              5693  1
18                    2834.2              6342  1
19                    9118.1              9304  1
20                    1600.8              4719  1
21                     308.3               836  1
22                    1403.6              2808  1
23                    3421.6              8169  1
24                     689.8              3757  1
25                    1188.9              4483  1
26                      89.7               281  1
27                    1522.0              3735  1
28                     717.5              2606  1
29                     180.1               548  1
30                     199.0               604  1
31                     727.6              2050  1
为什么当我输入> z=predict(lm.j,data.frame(x$进=y))会出现下面这样的错误提醒呢
错误: 意外的'=' in "z=predict(lm.j,data.frame(x$进="
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:数据框 小问题 社会消费品零售总额 predict 固定资产投资 内蒙古 人均GDP 黑龙江

沙发
qoiqpwqr 发表于 2013-11-7 01:01:31
完整的变量名又不是“进“。

藤椅
qoiqpwqr 发表于 2013-11-7 01:02:06
推荐不要用中文的变量名。

板凳
红与黑的铭记 发表于 2013-11-7 09:38:20
qoiqpwqr 发表于 2013-11-7 01:02
推荐不要用中文的变量名。
额,但是我换成想x[[3]]也不行,应该不是变量名的原因,这个是可以这么取得额

报纸
qoiqpwqr 发表于 2013-11-7 12:19:22
红与黑的铭记 发表于 2013-11-7 09:38
额,但是我换成想x[[3]]也不行,应该不是变量名的原因,这个是可以这么取得额
x[, 3]

地板
zhangyangsmith 发表于 2013-11-7 16:33:57
"==" instead of "="?

7
红与黑的铭记 发表于 2013-11-8 09:22:51
zhangyangsmith 发表于 2013-11-7 16:33
"==" instead of "="?
不行呢,书上有个例也是和我一样这么赋值的,改成这样,会出现两个警告

8
ywh19860616 发表于 2013-11-8 10:10:50
红与黑的铭记 发表于 2013-11-8 09:22
不行呢,书上有个例也是和我一样这么赋值的,改成这样,会出现两个警告
友情提示,把数据用excel传上来,这样方便别人试,而且很快就知道问题,
不用这样猜来猜去的。
一份耕耘,一份收获。

9
jgchen1966 发表于 2013-11-8 12:35:00
R 本身内容多样丰富,有此基本的,在使用中严格标准化,如:data.frame ,仔细读完下文,就不会有问题:
Details
A data frame is a list of variables of the same number of rows with unique row names, given class
"data.frame". If no variables are included, the row names determine the number of rows.
The column names should be non-empty, and attempts to use empty names will have unsupported
results. Duplicate column names are allowed, but you need to use check.names = FALSE for
data.frame to generate such a data frame. However, not all operations on data frames will preserve
duplicated column names: for example matrix-like subsetting will force column names in the result
to be unique.
data.frame converts each of its arguments to a data frame by calling
as.data.frame(optional = TRUE). As that is a generic function, methods can be written
to change the behaviour of arguments according to their classes: R comes with many such methods.
Character variables passed to data.frame are converted to factor columns unless protected by I or
argument stringsAsFactors is false. If a list or data frame or matrix is passed to data.frame it
is as if each component or column had been passed as a separate argument (except for matrices of
class "model.matrix" and those protected by I).
Objects passed to data.frame should have the same number of rows, but atomic vectors, factors and
character vectors protected by I will be recycled a whole number of times if necessary (including
as elements of list arguments).
If row names are not supplied in the call to data.frame, the row names are taken from the first
component that has suitable names, for example a named vector or a matrix with rownames or a
data frame. (If that component is subsequently recycled, the names are discarded with a warning.)
If row.names was supplied as NULL or no suitable component was found the row names are the
integer sequence starting at one (and such row names are considered to be ‘automatic’, and not
preserved by as.matrix).
If row names are supplied of length one and the data frame has a single row, the row.names is taken
to specify the row names and not a column (by name or number).
Names are removed from vector inputs not protected by I.
default.stringsAsFactors is a utility that takes getOption("stringsAsFactors") and ensures
the result is TRUE or FALSE (or throws an error if the value is not NULL).
鹑居鷇食,鸟行无彰

10
jgchen1966 发表于 2013-11-8 12:40:35
z=predict(lm.j,data.frame(进=y))   如此应行了,多了X$ !! data.frame 中定义data.frame ,就可能有错
鹑居鷇食,鸟行无彰

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 14:15