gpt4 book ai didi

sql - data.frame structure fubar : structure says most character, 打印说只有一些

转载 作者:行者123 更新时间:2023-12-02 07:45:28 25 4
gpt4 key购买 nike

我正在使用 sqldf 对一个巨大的文件进行子集化。以下命令为我提供了一个 100 行和 42 列的 data.frame。

first <- read.csv.sql("first.txt", sep = " ", header = TRUE, row.names = FALSE,
sql = "SELECT * FROM file WHERE n = '\"n63\"' AND ratio = 1 AND r_name = '\"r1\"' AND method = '\"nearest\"' AND variables = 10")

对象的结构是

'data.frame':   100 obs. of  42 variables:
$ test_before : chr "TRUE" "TRUE" "TRUE" "TRUE" ...
$ test_after : chr "TRUE" "TRUE" "TRUE" "TRUE" ...
$ meanPSmatchRATIO : chr "1.54845330373635" "1.16857102212364" "1.25330045961256" "1.8011651466717" ...
snipped intervening normally printed columns
$ PSdiff_DIFF : chr "-0.0103938442562762" "-0.00935228868105753" "-0.00947571480267878"
snipped intervening normally printed columns
$ nUNMATCHt : chr "0" "0" "0" "0" ...
$ caliper : chr "\"no\"" "\"no\"" "\"no\"" "\"no\"" ...
$ method : chr "\"nearest\"" "\"nearest\"" "\"nearest\"" "\"nearest\"" ...
$ r_name : chr "\"r1\"" "\"r1\"" "\"r1\"" "\"r1\"" ...
$ ratio : int 1 1 1 1 1 1 1 1 1 1 ...
$ n : chr "\"n63\"" "\"n63\"" "\"n63\"" "\"n63\"" ...
$ variables : int 10 10 10 10 10 10 10 10 10 10 ...

现在,基于此,您会期望当我打印 data.frame 时,所有列(除了那些 int 将是字符(包含在“”)中)。但你错了!

  test_before test_after meanPSmatchRATIO del-  nUNMATCHt caliper    method r_name ratio     n variables
1 TRUE TRUE 1.54845330373635 eted 0 "no" "nearest" "r1" 1 "n63" 10
2 TRUE TRUE 1.16857102212364 ... 0 "no" "nearest" "r1" 1 "n63" 10
3 TRUE TRUE 1.25330045961256 ... 0 "no" "nearest" "r1" 1 "n63" 10
4 TRUE TRUE 1.8011651466717 ...t 0 "no" "nearest" "r1" 1 "n63" 10

请注意,只有最后几列是“字符”。我对发生的事情有点迷茫。谁能解释一下?

最佳答案

我觉得不错。 print.data.frame 通常不会为字符列打印引号,但最后几列嵌入了引号,因此它们显示默认为“引号”。

Data <- data.frame(x=1:5,y=as.character(1:5),
z=letters[1:5], q=paste("\"",letters[1:5],"\"",sep=""))
print(Data) # default print
# x y z q
# 1 1 1 a "a"
# 2 2 2 b "b"
# 3 3 3 c "c"
# 4 4 4 d "d"
# 5 5 5 e "e"
print(Data, quote=TRUE) # show embedded quotes
# x y z q
# 1 "1" "1" "a" "\"a\""
# 2 "2" "2" "b" "\"b\""
# 3 "3" "3" "c" "\"c\""
# 4 "4" "4" "d" "\"d\""
# 5 "5" "5" "e" "\"e\""

关于sql - data.frame structure fubar : structure says most character, 打印说只有一些,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7379083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com