我有两种方法可以从excel文件中访问数据。第一种方法是简单的方法:
easy.way <- read.csv(file="flanker1.csv",header=TRUE)
另一个是索引:
file.number <- c(1)
index.way <-setNames(lapply(paste0("flanker", file.number,".csv"),read.csv),paste0(file.number,'participant'))
两个输出看起来都一样(我无法发布图片,因为我的声誉太低了。)当我尝试访问数据时会出现问题。例如:
length(test$block) # length = 400, works
length(data[1]$block) # length = 0, doesn't work
为什么我无法通过索引访问有关数据框的信息,但如果使用标准变量则没有问题?
编辑:
STR(试验):
'data.frame': 400 obs. of 10 variables:
$ trial : int 0 1 2 3 4 5 6 7 8 9 ...
$ distractor.direction: int 2 1 1 2 2 1 1 2 2 2 ...
$ target.direction : int 1 2 2 1 2 1 2 1 1 1 ...
$ fixcross.time : int 2 1 2 3 2 4 2 2 2 2 ...
$ intertrial.interval : int 2 1 1 2 1 4 3 3 4 1 ...
$ type : Factor w/ 2 levels "congruent","incongruent": 2 2 2 2 2 1 2 2 2 2 ...
$ keypress : Factor w/ 2 levels "['a']","['l']": 1 1 1 1 1 2 1 2 2 2 ...
$ accuracy : Factor w/ 2 levels "correct","incorrect": 2 1 1 2 1 1 1 1 1 1 ...
$ rt : num 0.325 0.433 0.359 0.315 0.501 ...
$ block : Factor w/ 2 levels "delay","no delay": 1 1 1 1 1 1 1 1 1 1 ...
STR(数据[1]):
List of 1
$ 1 participant:'data.frame': 400 obs. of 10 variables:
..$ trial : int [1:400] 0 1 2 3 4 5 6 7 8 9 ...
..$ distractor.direction: int [1:400] 2 1 1 2 2 1 1 2 2 2 ...
..$ target.direction : int [1:400] 1 2 2 1 2 1 2 1 1 1 ...
..$ fixcross.time : int [1:400] 2 1 2 3 2 4 2 2 2 2 ...
..$ intertrial.interval : int [1:400] 2 1 1 2 1 4 3 3 4 1 ...
..$ type : chr [1:400] "incongruent" "incongruent" "incongruent" "incongruent" ...
..$ keypress : chr [1:400] "['a']" "['a']" "['a']" "['a']" ...
..$ accuracy : chr [1:400] "incorrect" "correct" "correct" "incorrect" ...
..$ rt : num [1:400] 0.325 0.433 0.359 0.315 0.501 ...
..$ block : chr [1:400] "delay" "delay" "delay" "delay" ...
答案 0 :(得分:1)
我认为您需要使用双括号表示法。 data[[1]]$block
应该有效