drop
Builtin index · Collections & strings
result = take(xs, n)
Input: xs, n · Output: result
What it is
xs is a Vec/List; n is a number of elements.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = take(xs, n) | xs Vec or Listxs is a Vec/List.n numbern is a number of elements. | result — | Returns the same type as xs: the first n elements (take) or everything after them (drop). n beyond the length is clamped, not an error. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
write_csv(table(
temp = [21.5, 22.1, 35.0, 21.8, 36.2, 22.0, 34.5, 21.6, 35.8, 22.3],
humidity = [45.2, 46.0, 20.1, 45.5, 19.5, 45.8, 21.0, 45.1, 20.4, 46.2],
pressure = [1012.1, 1011.8, 1009.5, 1012.0, 1008.9, 1012.3, 1009.8, 1012.2, 1009.1, 1011.9],
label = ["ok", "ok", "warn", "ok", "warn", "ok", "warn", "ok", "warn", "ok"]
), "sensors.csv")
df = read_csv("sensors.csv")
print("rows = {nrow(df)}, cols = {ncol(df)}")
print(head(df, 3))
numeric = drop(df, "label")
c = corrmat(numeric)
print(c.matrix)
c.plot()
savefig("quickstart_corrmat.svg")
scaled_temp = standardize(df.temp)
print("standardized temp[0] = {scaled_temp[0]:.4f}")
print("mean(standardized) = {mean(scaled_temp):.4f}, std(standardized) = {std(scaled_temp):.4f}")
rows = 10, cols = 4 temp humidity pressure label ---- -------- -------- ----- 21.5 45.2 1012.1 ok 22.1 46 1011.8 ok 35 20.1 1009.5 warn [1, -0.997357, -0.991317; -0.997357, 1, 0.983511; -0.991317, 0.983511, 1] · savefig quickstart_corrmat.svg note: fonts render using whatever is installed on the viewer's machine (none are embedded) -- pass embed_fonts=true (fontfamily preset only) or export .tikz for guaranteed appearance standardized temp[0] = -0.8275 mean(standardized) = -0.0000, std(standardized) = 1.0000
from quickstart
How it works
data.drop("col") / data.drop(("col1", "col2")) — a new Table with the named column(s) removed (see Table::drop's own doc comment). Accepts either shape for the "which columns" argument: select's own convention of N trailing positional args (select(df, "a", "b")), or a single list value for "drop several at once" — column_names_arg below expands that one case, everything else stays identical to select's display_value-per-arg collection. The list form is a parenthesized tuple (("a", "b"), Qu's existing Value::List literal), NOT a bracketed [...] — [...] is always a numeric Vec/Mat literal here (eval_matrix_literal calls .as_num() on every cell), so ["a", "b"] with string cells already errors before reaching this builtin at all; there is no bracketed string-list literal to accept.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.
See also
take — documented in the same entry.