This look really interesting but I don't understand what is happening.
Please can someone explain the last line and what the bit in [] is doing.
Ian
df = data.frame( A=c('a','b','c'), B=c(1,2,3), C=c(10,20,30),
stringsAsFactors=FALSE)
newrow = c('X', 100, 200)
rbind(df,newrow)[c(1,4,2,3),]
___
I think, here is the solution. If NA is included in read.table list the row
becomes a factor:
$ Q21: Factor w/ 3 levels " 1"," 2"," NA": 1 2 3 2 2. This will not work
with rowSums.
If I put the missing value as a blank, then it is still read as NA but the
whole row is considered as an integer an
Hi,
Thanks, your method does indeed work. Thank you.
Last night, I worked out something similar and found out about rowMeans as
well.
Kind wishes,
Ian
yy <- read.table( header = T, sep=",", text =
"Q20, Q21, Q22, Q23, Q24
0,1, 2,3,4
1,NA,2,3,4
2,1, 2,3,4
5,NA,3,NA,NA")
yy
Q20 Q21 Q22 Q23
I am fairly new to R and would like help with the problem below. I am
trying to sum and count several rows in the data frame yy below. All works
well as in example 1. When I try to add the columns, with an NA in Q21, I
get as NA as mySum. I would like NA to be treated as O, or igored.
I wrote
4 matches
Mail list logo