“R:数据读取与管理”的版本间的差异
来自OBHRM百科
Lichaoping(讨论 | 贡献) (→从文本文件读取自由格式的数据) |
Lichaoping(讨论 | 贡献) (→从文本文件读取自由格式的数据) |
||
第31行: | 第31行: | ||
如果您已经用 | 如果您已经用 | ||
− | <pre>mydata <- read.table("c:\\program files\\mplus\\mplus examples\\user's guide examples\\ex5.1.dat") | + | <pre>mydata <- read.table("c:\\program files\\mplus\\mplus examples\\user's guide examples\\ex5.1.dat") # 读取ex5.1.dat,注意目录 |
− | names(mydata) <-c(paste("item", 1:6, sep=""))</pre> | + | names(mydata) <-c(paste("item", 1:6, sep="")) # 为变量命名,6个变量从item1到item6</pre> |
2017年3月4日 (六) 09:45的版本
从文本文件读取固定格式的数据
示例数据
010103643424242343243334 23333344343244333434444433 33334333343333334433333222 1211316013333114213 010103533434332332 23432 243433334234 3334244434433 43222333332242323343322334 2232323233433336213 06 010103443334442234343434 22444224344342343334443433 43222444443434344444444222 02212011223222132242 10
示例数据说明
所有数据分为四行,具体为: 第一行:company 1-2 group 3-4 num 5-7 item1 to item17 8-24 第二行:item18 to item43 1-26 第三行:item44 to item69 1-26 第四行:mbi1 to mbi16 1-16 sex 17 age 18 edu 19 manage 20 year 21-22 month 23-24
数据读取方法
mydata <- read.fortran("D:\\01a.txt",list( c("2F2.0", "F3.0", "17F1.0"), c("26F1.0"), c("26F1.0"), c("20F1.0","2F2.0"))) names(mydata) <-c("company", "group","no",paste("item", 1:69, sep=""),paste("mbi", 1:16,sep=""),"sex","age","edu","manager","year","month")
从文本文件读取自由格式的数据
如果您已经用
mydata <- read.table("c:\\program files\\mplus\\mplus examples\\user's guide examples\\ex5.1.dat") # 读取ex5.1.dat,注意目录 names(mydata) <-c(paste("item", 1:6, sep="")) # 为变量命名,6个变量从item1到item6