pengchy 在win平台下,可以这样使用: test <- data.frame() test[1,1] <- 12 #可以按照顺序给test的各个元素赋值 而在linux下,则不可以。 另外,下面的错误不知为什么 test <- data.frame(mir1=paste("a",1:16,sep="")) test[1,1] <- "a" Warning message: invalid factor level, NAs generated in: `[<-.factor`(`*tmp*`, iseq, value = "a")
yihui 第一个错误请给出错误信息。 第二个: test=data.frame(mir1=paste("a",1:16,sep=""), stringsAsFactors=F)就可以了 data.frame()函数默认会把字符串转化为factor类型,一旦成为factor,你就不能给它赋值为这个factor所有levels之外的任何值,如 > x=factor(LETTERS) > x [1] A B C D E F G H I J K L M N O P Q R S T U V W X Y Z Levels: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z > x[1]='aa' # 'aa'不在x所有的levels中,所以不能赋这个值 Warning message: invalid factor level, NAs generated in: `[<-.factor`(`*tmp*`, 1, value = "aa") > x[1]='B' #'B'是所有levels之一 > x [1] B B C D E F G H I J K L M N O P Q R S T U V W X Y Z Levels: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
pengchy 多谢!我再看看R教材 <br /> > test <- data.frame()<br /> > test[1,1] <- 12<br /> Error in x[[i]] : subscript out of bounds<br />
rtist [quote]引用第6楼fu_neng于2007-08-28 03:11发表的“”: 我的r2.3 就不能对空数据框赋值 test <- data.frame() test[1,1] <- 12 显示下标越界. o[/quote] 2.5以后应该可以了