我有这个代码Typescript:
const [history, setHistory] = useState([Array(9).fill(null)]);
Run Code Online (Sandbox Code Playgroud)
const newHistory = history.slice(0, currentStep + 1);
Run Code Online (Sandbox Code Playgroud)
当我想使用这样的扩展运算符设置新状态时:
setHistory(...newHistory);
Run Code Online (Sandbox Code Playgroud)
我有错误:
扩展参数必须具有元组类型或传递给剩余参数。
有人可以帮助我,我如何正确输入这个?
当我尝试在打字稿中使用传播时,例如:
.reduce((unique, x) => {
unique.some(element => element.machineName === x.machineName) ? unique : [...unique, x];
}
Run Code Online (Sandbox Code Playgroud)
我收到红色标记的警告Visual Studio Code:
the syntax requires an imported helper named __spreadArrays
typescript version: "2.3.4"
target: "es5"
Run Code Online (Sandbox Code Playgroud)
我认为在以后的版本中这个问题是固定的,但现在我无法迁移。我该如何解决?
注意:项目编译得很好并且工作正常。但红色的底层VS Code在烦人。
以下是此示例的玩具数据集:
data <- data.frame(x=rep(c("red","blue","green"),each=4), y=rep(letters[1:4],3), value.1 = 1:12, value.2 = 13:24)
x y value.1 value.2
1 red a 1 13
2 red b 2 14
3 red c 3 15
4 red d 4 16
5 blue a 5 17
6 blue b 6 18
7 blue c 7 19
8 blue d 8 20
9 green a 9 21
10 green b 10 22
11 green c 11 23
12 green d 12 24
Run Code Online (Sandbox Code Playgroud)
如何转换或传播变量y,以生成以下宽数据.frame:
x a.value.1 b.value.1 c.value.1 …Run Code Online (Sandbox Code Playgroud) 我试图将具有列名称的对象传递给spread函数,但是它不是读取对象内部的值而只是尝试使用对象名称本身
这里只是一个玩具示例
library(tidyr)
d = (1:4)
n = c("a"," a", "b","b")
s = c(1, 2,5,7)
df = data.frame(d,n, s)
Value <- n
data_wide <- spread(df, Value , s)
Run Code Online (Sandbox Code Playgroud)
错误:输入中不存在键列"值".
虽然下面工作正常:
data_wide <- spread(df, n, s)
d a a b
1 1 NA 1 NA
2 2 2 NA NA
3 3 NA NA 5
4 4 NA NA 7
Run Code Online (Sandbox Code Playgroud) 我正在尝试在Mathematica中编写一个程序,它将模拟带电球轴承在充电时充电的方式(它们相互排斥).到目前为止,我的程序使滚珠轴承不会从屏幕上移开,并计算它们撞到盒子侧面的次数.到目前为止,我的球轴承随机移动,但我需要知道如何使它们相互排斥.
到目前为止,这是我的代码:
Manipulate[
(*If the number of points has been reduced, discard points*)
If[ballcount < Length[contents],
contents = Take[contents, ballcount]];
(*If the number of points has been increased, generate some random points*)
If[ballcount > Length[contents],
contents =
Join[contents,
Table[{RandomReal[{-size, size}, {2}], {Cos[#], Sin[#]} &[
RandomReal[{0, 2 \[Pi]}]]}, {ballcount - Length[contents]}]]];
Grid[{{Graphics[{PointSize[0.02],
(*Draw the container*)
Line[size {{-1, -1}, {1, -1}, {1, 1}, {-1, 1}, {-1, -1}}],
Blend[{Blue, Red}, charge/0.3],
Point[
(*Start the main dynamic actions*)
Dynamic[
(*Reset the collision counter*)
collision …Run Code Online (Sandbox Code Playgroud) 我在pandas中的pd.pivot()或pivot_table()函数遇到了一些问题.
我有这个:
df = pd.DataFrame({'site_id': {0: 'a', 1: 'a', 2: 'b', 3: 'b', 4: 'c', 5:
'c',6: 'a', 7: 'a', 8: 'b', 9: 'b', 10: 'c', 11: 'c'},
'dt': {0: 1, 1: 1, 2: 1, 3: 1, 4: 1, 5: 1,6: 2, 7: 2, 8: 2, 9: 2, 10: 2, 11: 2},
'eu': {0: 'FGE', 1: 'WSH', 2: 'FGE', 3: 'WSH', 4: 'FGE', 5: 'WSH',6: 'FGE', 7: 'WSH', 8: 'FGE', 9: 'WSH', 10: 'FGE', 11: 'WSH'},
'kw': {0: '8', 1: …Run Code Online (Sandbox Code Playgroud) 已经有关于这个主题的问题之前这儿,但我仍然有传播这种挣扎.我希望每个state人都有自己的温度值列.
这是dput()我的一个数据.我会叫它df
structure(list(date = c("2018-01-21", "2018-01-21", "2018-01-20",
"2018-01-20", "2018-01-19", "2018-01-19", "2018-01-18", "2018-01-18",
"2018-01-17", "2018-01-17", "2018-01-16", "2018-01-16", "2018-01-15",
"2018-01-15", "2018-01-14", "2018-01-14", "2018-01-12", "2018-01-12",
"2018-01-11", "2018-01-11", "2018-01-10", "2018-01-10", "2018-01-09",
"2018-01-09", "2018-01-08", "2018-01-08", "2018-01-07", "2018-01-07",
"2018-01-06", "2018-01-06", "2018-01-05", "2018-01-05", "2018-01-04",
"2018-01-04", "2018-01-03", "2018-01-03", "2018-01-03", "2018-01-03",
"2018-01-02", "2018-01-02"), tmin = c(24, 31, 31, 29, 44, 17,
32, 7, 31, 7, 31, 6, 30, 13, 30, 1, 43, 20, 33, 52, 42, 29, 30,
29, 26, 32, 33, …Run Code Online (Sandbox Code Playgroud) 如何更改以下表格:
Type Name Answer n
TypeA Apple Yes 5
TypeA Apple No 10
TypeA Apple DK 8
TypeA Apple NA 20
TypeA Orange Yes 6
TypeA Orange No 11
TypeA Orange DK 8
TypeA Orange NA 23
Run Code Online (Sandbox Code Playgroud)
改成:
Type Name Yes No DK NA
TypeA Apple 5 10 8 20
TypeA Orange 6 11 8 23
Run Code Online (Sandbox Code Playgroud)
我使用以下代码来获取第一个表.
df_1 <-
df %>%
group_by(Type, Name, Answer) %>%
tally()
Run Code Online (Sandbox Code Playgroud)
然后我尝试使用spread命令到达第二个表,但是我收到以下错误消息:
"错误:所有列都必须命名为"
df_2 <- spread(df_1, Answer)
Run Code Online (Sandbox Code Playgroud) 我想知道在 JavaScript 中使用带有数组的 spread 的时间复杂度是多少。它是线性 O(n) 还是常数 O(1)?
下面的语法示例:
let lar = Math.max(...nums)
Run Code Online (Sandbox Code Playgroud) 我有一个数组中的对象状态(在我的 ReduxReducer 中)。
const initialState = {
items: [
{ id: 1, dish: "General Chicken", price: 12.1, quantity: 0 },
{ id: 2, dish: "Chicken & Broccoli", price: 10.76, quantity: 0 },
{ id: 3, dish: "Mandaran Combination", price: 15.25, quantity: 0 },
{ id: 4, dish: "Szechuan Chicken", price: 9.5, quantity: 0 }
],
addedItems: [],
total: 0
};
Run Code Online (Sandbox Code Playgroud)
我有一个操作,当在 Cart.jsx 中单击按钮时,将对象的数量加 1,例如 {id:1,菜:Generals Chicken,价格:10.76,数量:0}。这是我尝试使用展开运算符的第一个Reducer:
case "ADD_QUANTITY":
let existing_item = state.addedItems.find(
item => action.payload === item.id
);
return { …Run Code Online (Sandbox Code Playgroud) spread ×10
r ×4
javascript ×3
tidyr ×3
dplyr ×2
reactjs ×2
typescript ×2
arrays ×1
casting ×1
dictionary ×1
pandas ×1
physics ×1
pivot ×1
point ×1
python-3.x ×1
react-redux ×1
reshape2 ×1
tidy ×1