You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在RStudio中使用向量创建指定学生资助统计表格?

Solution to Create Your Student Financial Assistance Table

Here's how to complete your code to generate the exact table you want in RStudio:

First, let's fix the code to properly build a structured table (since setNames is for naming vectors, not creating data frames):

# Your existing vectors
Students1 <- c("with_Pell_Grant","without_Pell_Grant","with_loan", "without_loan")
Percentage1 <- c(0.4059046, 0.5018954, 0.4053371, 0.2290538)
financial_assistance1 <- c('True', 'True', 'False', 'False')

# Create a data frame with your columns
student_finance <- data.frame(
  Students = Students1,
  Percentage = Percentage1,
  `Financial Assistance` = financial_assistance1,
  stringsAsFactors = FALSE  # Keeps text columns as plain strings instead of factors
)

# Add the "序号" (serial number) column at the beginning
student_finance <- cbind(序号 = 1:nrow(student_finance), student_finance)

# View the formatted table in RStudio's viewer pane
View(student_finance)

Quick Explanations:

  • data.frame() is the standard base R function to combine vectors into a table. The backticks around Financial Assistance let us use a column name with a space.
  • 1:nrow(student_finance) automatically generates sequential numbers for the "序号" column—this works even if you add more rows later.
  • If you want the Financial Assistance column to be a logical type (instead of text strings), update your vector to use uppercase TRUE/FALSE without quotes:
    financial_assistance1 <- c(TRUE, TRUE, FALSE, FALSE)
    

Run the full code, and you'll get a table that matches exactly what you requested. You can also print it directly to the console by typing student_finance after running the code.

内容的提问来源于stack exchange,提问作者Reeza

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:50:32