r - How to make a factor a numeric value? -
this sec time posting, hope "reproducible example" thing right.
here error,
error in if ((sound[i, 3] < -10 & sound[min(81, + 1), 3] > -10) | (sound[i, : missing value true/false needed in addition: warning messages: 1: in ops.factor(sound[i, 3], -10) : < not meaningful factors 2: in ops.factor(sound[min(81, + 1), 3], -10) : > not meaningful factors 3: in ops.factor(sound[i, 3], -10) : > not meaningful factors 4: in ops.factor(sound[min(81, + 1), 3], -10) : < not meaningful factors here code,
> for(i in 3:length(sound[,2])){ + if(sound[i,3]==-10){ + soundout[m,7]=sound[i,2] + m=m+1} + if((sound[i,3]< -10&sound[min(81,i+1),3]>-10)|(sound[i,3]>-10&sound[min(81,i+1),3]< -10)){ + soundout[m,7]=(10-sound[i,3])*(sound[i+1,2]-sound[i,2])/(sound[i+1,3]-sound[i,3])+sound[i,2] + m=m+1}} can please tell me how create factor sound[1,3] numeric value? give thanks you,
for illustration reproducible, need both code , data. right now, can't take code , run on machine , generate same error see (which meant having reproducible example). don't need give entire dataset, similar simple illustration 5-10 rows , necessary columns can see what's going on.
senor o absolutely right problem sound[, 3] factor. before running code posted, run this:
colnames(sound) <- sound[1, ] sound <- sound[-1:2, ] sound[, 2] <- as.numeric(as.character(sound[, 2])) sound[, 3] <- as.numeric(as.character(sound[, 3])) sound[, 7] <- as.numeric(as.character(sound[, 7])) that turn info want arithmetic operations on numbers. seems have headers or info don't want utilize in rows 1 , 2, coerced rows 3 , on columns utilize in loop.
edit: mrflick right it's possible prepare up-front when read data, without knowing kind of file you're reading , how you're doing can't should do. if you're reading csv file disk, though, set as.is = true , bring in numbers numeric, characters characters, etc.
r r-factor
No comments:
Post a Comment