Guest User

Untitled

a guest
Jan 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. ## Import files:
  2. temp = list.files(pattern="*.csv") #Filenames from working directory
  3. for (i in 1:length(temp)) {
  4. assign(temp[i], read.delim(temp[i],sep=";", header = T, nrows = 6)) #Clean data to include only RGB
  5. }
  6.  
  7. allvars <- ls(all.names = T) #List all variables
  8.  
  9. getClasses <- function(variable) { #Find RGB classes and name
  10. red <- variable$R[3:5]
  11. green <- variable$G[3:5]
  12. blue <- variable$B[3:5]
  13. classes <- data.frame(red, green, blue)
  14. print(classes)
  15. }
  16.  
  17. #This is where the problem happens:
  18. for (i in 1:length(allvars)) {
  19. assign(allvars[i], getClasses(allvars[i])) #Apply getClasses function to current variable and store new data
  20. }
  21. #Error: $ operator is invalid for atomic vectors
Add Comment
Please, Sign In to add comment